Skip to content

Schedule a Job

Sometimes you have a job that you want to run frequently. With AskAnna you can add a schedule to your askanna.yml configuration. On this page we will tell you how you can create schedules for a job and check the applied schedules for a job in the web interface.

Create a Schedule

In the definition of the job, you can optionally define a schedule:

name of the job:
  job:
    - ...
  schedule:
    - "@weekly"

Or multiple schedules:

name of the job:
  job:
    - ...
  schedule:
    - "@weekly"
    - day: 1
    - "0 8 * * *"

Schedule templates

In AskAnna we use cron to schedule jobs. Because cron syntax is not always easy to read, we added a couple of templates:

Name Cron expression
@midnight 0 0 * * *
@yearly 0 0 1 1 *
@annually 0 0 1 1 *
@monthly 0 0 1 * *
@weekly 0 0 * * 0
@daily 0 0 * * *
@hourly 0 * * * *

List using cron names

You can add a list with names that refer to the different cron names:

name of the job:
  job:
    - ...
  schedule:
    - minute: 10
      hour: 8
      day: "5-10"
      month: 12
      weekday: 1

The list example above translates into a schedule that runs at 08:10 on day-of-month from 5 through 10 and only on Monday.

You don't have to specify every item in the list. If you leave it empty, we will interpret it as * or every x. For example, the following definition will run every minute on the first day of the month:

name of the job:
  job:
    - ...
  schedule:
    - day: 1

Cron syntax

We also support the official cron syntax. Cron expressions looks like * * * * *. The syntax has 5 positions. Each position has it's own value:

Position Name Allowed values
1. Minute 0 - 59
2. Hour 0 - 23
3. Day (of the month) 1 -13
4. Month 1 - 12
5. Day of the week 0 - 6 (Sunday = 0, Monday = 1, ..., Saterday = 6)

Supported syntax for Cron (and also for the list using cron names values):

Value Description
* any value, for example day: * will run on any day
, list seperator, for example hour: "4,10,16" wil run on 04:00, 10:00 an 16:00
- range of values, for example hour: "8-17" will run every hour between 08:00 and 17:00
/ ste value, for example hour: */6 will run every 6th hour, so at 06:00, 12:00, 18:00 and 00:00

Cron editor

To make it easier to define or check a cron schedule, you can use the quick and simple editor for cron schedule expressions: crontab guru

Timezones

The AskAnna platform runs by default on servers that are configured to run on timezone UTC. If you want to run a job at a specific time in a timezone of your request, then you can configure this:

name of the job:
  job:
    - ...
  schedule:
    - hour: 8
  timezone: Europe/Amsterdam

For timezones, we use the tz database. In the askanna.yml config, you can refer to any TZ database name from the list of tz database time zones:

Open the list of TZ database time zones

Validate a Schedule

Since version 0.8.0 of the AskAnna CLI, we also support validation of the askanna.yml. Part of the validation is that we also validate the schedules.

Validation runs the moment you push code to your project in AskAnna. If you have specified an invalid schedule, the AskAnna CLI prints feedback in the terminal, so you know what to fix.

View active Schedules

When a job has a schedule, we also show it on the job page. Here you can find the date-time of the next run. Also, you can find the schedule or a list of schedules:

Job with a schedule

In the web interface you can check the schedules in a human-friendly format. When you point your mouse on a schedule, you can see the original definition and next run:

Job schedule meta

Runs triggered by a schedule

If a schedule triggers a run, this information is available. When you request the runinfo in the response, you will see the trigger value set to SCHEDULE. This information is also shown on the run page:

Run triggered by a schedule

In AskAnna we check every minute if we should trigger new runs. If somehow, for example a job was not triggered because of a system restart or interruption, we will do a check every 5 minutes if we might have missed to trigger a new run. If that's the case, we will make sure it is triggered on the next schedule.