Advanced Schedules (Cron Expressions)
First published on: 08/24/2023/8:35 am
The Saltbox Scheduler is well-versed in meeting the needs of most average integrations. There are many ways to schedule workflows, like running every X minutes and every day at X time.
However, there are scenario gaps these settings don't cover (e.g., only running between certain hours of the day or running at multiple specific times each day). If your scenario isn’t covered by the out-of-the-box settings, you can likely create a “Cron Expression” that covers it.
What are Cron expressions?
Cron expressions are a syntax or formula made of 5 parts, with each part making up a specific time interval.
Graphically represented in the simplest format, it looks like this.
A Cron expression of 1**** would make your workflow run one minute past the hour, every hour.
It gets more complicated, as additional syntax can make these more sophisticated (and complex). You'll find a reference to the operators you can use at the bottom of this document.
We can't publish every eventuality, but here are a few scenarios the Saltbox Scheduler doesn't cover.
I want my workflow to run every 15 minutes, but not at the hour, quarter past, half past, etc.; it should run at 5 minutes, 20 minutes, 35 minutes, and 50 minutes past. This can be entered as 5,20,35,50 * * * *
If I want a workflow to run every minute between 0900 and 1700, I can use 0-59 9-17 * * *
- 0-59 represents a range of 0-59 minutes past the hour
- 9-17 represents a range of between the hours of 0900 and 1700
If I want a workflow to run every minute past the hour between 0900 and 1700 Monday to Friday, I could enter it as 0-59 9-17 * * 1-5, where 1-5 represents Monday to Friday.
There’s a lot you can do with this, including commands for multiple values, hyphens (-) for ranges, and separators (/) to divide values (e.g., */12 in the hour column represents every 12 hours).
If you need to use Cron expressions and are new to it, we recommend using an online Cron generator, such as the one here: https://crontab.guru/.
SOME APPLICATIONS HAVE A 6TH PART REPRESENTED as 6 * * * * * *. IN THIS CASE, THE FIRST ASTERISK REPRESENTS SECONDS. HOWEVER, SALTBOX DOESN'T SUPPORT SECONDS.
Reference Cron Operators
- Asterisk (*). Signify all possible values in a field. For example, if you want your Cron job to run every minute, write an asterisk in the minute field.
- Comma (,). List multiple values. For example, write "1,5" in the day of the week field to schedule the task for every Monday and Friday.
- Hyphen (-). Determine a range of values. For example, if you want to set up a Cron job from June to September, write 6-9 in the month field.
- Separator (/). Divide a value. For example, write */12 in the hour field to make a script run every twelve hours.
- Last (L). Can be used in the day-of-month and day-of-week fields. For example, writing 3L in the day-of-week field means the last Wednesday of a month.
- Weekday (W). Determine the closest weekday from a given time. For example, if the 1st of a month is a Saturday, write 1W in the day-of-month field to run the command on the following Monday (the 3rd).
- Hash (#). Determine the day of the week, followed by a number ranging from 1 to 5. For example, 1#2 means the second Monday of the month.
- Question mark (?). Use this operator to input “no specific value” for the “day of the month” and “day of the week” fields.
Last modified: 03/25/2025/12:52 pm |