Introduction to Cron Expressions
Overview
Cron expressions are used for scheduling and automating tasks to run at a specific time/date. Cron expressions consist of 5 to 6 subexpressions that describe the details of the schedule. These subexpressions might be further modified or replaced by specific special characters. Unqork supports the use of Cron expressions to schedule Timer Start and Timer node tasks in Workflow. Schedules in Unqork use the UTC (Coordinated Universal Time) time zone.
What You'll Learn
In this article, you’ll learn how to:
- Format Cron expressions in Unqork.
- Use Cron expressions with Timer nodes in Workflow.
- View examples of Cron expressions.
Formatting Cron Expressions in Unqork
Cron expressions in Unqork function similarly to how it is used for other services. A set of values called subexpressions dictate the date and time a task is performed. In Unqork, the Workflow Timer Start and Timer Nodes support Cron expressions.
To learn more about Timer Start and Timer nodes, visit our Timer Start Node and Timer Node articles.
The format for Cron expressions in the Unqork Designer Platform is:
* * * * * *
┬ ┬ ┬ ┬ ┬ ┬
│ │ │ │ │ |
│ │ │ │ │ └ Day-of-week
│ │ │ │ └───── Month
│ │ │ └────────── Day-of-month
│ │ └─────────────── Hour
│ └──────────────────── Minute
└───────────────────────── Second
The requirements, subexpression values, and special characters Unqork supports for Cron are:
Subexpression Field | Required | Values | Supported Special Characters |
---|---|---|---|
Second |
Optional |
0-59 (in seconds) |
, - * / |
Minute |
Required |
0-59 (in minutes) |
, - * / |
Hour |
Required |
0-23 (in a 24 hour period) |
, - * / |
Day-of-month |
Required |
0-31 |
, - * ? / L |
Month |
Required |
1-12 |
, - * / |
Day-of-week |
Required |
0-6 (0 is Sunday, 6 is Saturday) |
, - * ? / L # |
The function for each special character is:
Special Character | Meaning | Description | Example |
---|---|---|---|
, |
Multiple Values |
Allows multiple values. |
Inserting 12,14, 6 in the <hour> field indicates the hours 12pm, 2pm, and 4 pm. |
- |
Range |
Represents a continuous range of values. |
Using 12-14 in the <hour> field indicates the hours 12pm, 1pm, and 2pm. |
* |
All |
The schedule runs for every time unit. |
Placing a * in the <minute> field indicates the schedule to run every minute. |
/ |
Increment |
The amount by which to increment the values of a field. |
A <minute> expression of */10 indicates the minutes 0, 10, 20, 30, etc. |
? |
Any |
Representing an arbitrary value. |
A ? in the <day-of-month> field does not use the day-of-month for deciding the schedule. |
L |
Last |
Last occurrence of this weekday for the month in progress. |
The expression 0 0 * * * 6L indicates the schedule runs on the last Saturday of the month at midnight. |
# |
Nth Weekday |
Specifies the Nth weekday of the month. |
The value of 0#2 in the day-of-week field means the second Sunday of the month (Day 0 = Sunday and #2 = the 2nd one in the month). If you use the '#' character, you can define only one expression in the day-of-week field. For example, 3#1,6#3 is not valid because it is interpreted as two expressions. |
Using Cron Expressions With Timer and Timer Start Nodes in Workflow
Unqork Designer Platform Workflow Timer and Timer Start nodes support the use of Cron. To build a Cron expression in Unqork, specify the values for each subexpression in a single line, with spaces between each subexpression. For example, to schedule a task that is performed every two hours, every day, your expression looks like this: 0 0 0/2 * * ?
To use Cron with a Timer or Timer Start node:
1. | On the Workflow page, select or add a Timer Start/Timer node. |
2. | Click the Edit button to open the node configuration window. |
3. | Click the Cron button. |
4. | In the Cron expression field, insert a Cron Expression. For example: to make a schedule that fires every two hours, use the expression: 0 0 0/2 * * ?. |
A valid Cron Expression displays a green check mark and describes the schedule below the Cron expression field.
5. | Click Close. |
6. | Click the Save Workflow button to save your work. |
Examples of Cron Expressions in Unqork
The table below offers a list of common expressions to use for an application:
Expression | Description |
---|---|
0 0 12 * * ? |
Fire at 12:00 pm every day. |
0 15 12 * * ? |
Fire at 12:15 pm every day. |
0 * 18 * * ? |
Fire every minute starting at 6:00 pm and ending at 6:59 pm, every day. |
0 0/5 14 * * ? |
Fire every 5 minutes starting at 2:00 pm and ending at 2:55 pm, every day. |
0 0/5 16,18 * * ? |
Fire every 5 minutes starting at 4:00 pm and ending at 4:55 pm, and fire every 5 minutes starting at 6:00 pm and ending at 6:55 pm, every day. |
0 0-5 12 * * ? |
Fire every minute starting at 12:00 pm and ending at 12:05 pm, every day. |
0 25 10 15 * ? |
Fire at 10:25 am on the 15th day of every month. |
0 25 10 L * ? |
Fire at 10:25 am on the last day of every month. |
0 0 9 ? * 6#3 |
Fire at 9:00 am on the third Saturday of every month. |
0 0 12 * 2 ? |
Fire at 12:00 am every day of February. |
0 0 12 1/5 * ? |
Fire at 12 pm every 5 days every month, starting on the first day of the month. |
Resources