Zenaton white logo

Scheduling

Overview

The Zenaton scheduler allows you to create schedules to run tasks and workflows on a recurrent basis.

Normally you would immediately dispatch a workflow or a task using the dispatch function but you can also create a schedule so that the workflow or task is automatically dispatched at defined occurrences.

This is useful for processes that you would normally run using cron jobs, for example:

  • generate daily / weekly / monthly reports
  • update cached data on a regular basis
  • cleanup a database every week
  • launch a website scraping workflow every night

The Zenaton scheduler provides a straightforward way to launch recurrent tasks and workflows by writing it into your code. The scheduler can provide an added level of dependability when combined with other Zenaton features such as automatic retry and alerting.

Creating a schedule

Create a schedule for any tasks and workflows with the schedule function by passing a cron string:

(new RecurrentWorkflow())->schedule('* * * * * *');
new RecurrentWorkflow().schedule('* * * * * *');
RecurrentWorkflow.new.schedule('* * * * * *')
RecurrentWorkflow().schedule('* * * * * *')

The cron string parameter will define when the dispatches will occur. See the cron format section to see a complete reference of the format.

Managing Schedules

You can pause, resume and delete any created schedules on the Schedules tab on your dashboard.

Scheduling dashboard

When a schedule is paused, future instances of the task or workflow will not be dispatched until the schedule has been resumed.

When a schedule has been deleted, no new instances of the task or workflow will be dispatched and the schedule will disapear on your dashboard. If you want to schedule your task or workflow afterward, you would need to create a new schedule.

Note that the scheduler dispatches the linked task or workflow even if the previous execution isn’t finished.

Note also that automatic-retry can lead to overlaps, you should setup your retry policy according to the schedule occurence.

Cron format

When calling the schedule function you need to pass a cron string. Zenaton uses the following cron format to schedule tasks and workflows:


 * * * * * *
 | | | | | |
 | | | | | +-- Year                range: 1970-2099         wildcards: , - * /
 | | | | +---- Day of the Week     range: 0-6 or SUN-SAT    wildcards: , - * L #
 | | | +------ Month of the Year   range: 1-12 or JAN-DEC   wildcards: , - * /
 | | +-------- Day of the Month    range: 1-31              wildcards: , - * / L W
 | +---------- Hour                range: 0-23              wildcards: , - * /
 +------------ Minute              range: 0-59              wildcards: , - * /

 Supported alias are:
 - @minutely   run once a minute
 - @hourly     run once an hour
 - @daily      run once a day
 - @midnight   run once a day, same as @daily
 - @monthly    run once a month
 - @weekly     run once a week
 - @yearly     run once a year
 - @annually   run once a year, same as @yearly
All schedules use UTC time zone and the minimum precision for schedules is 1 minute.

View cron expression reference for more informations.

You can also use this tool to help you build your cron expressions.