Introduction
FME Flow uses the Quartz Scheduler library for scheduling jobs. This library supports CRON, a time-based job scheduler commonly found in UNIX-like operating systems. CRON expressions allow users to define precise schedules - such as running a workspace only on the first Monday of each month or at specific intervals during business hours - with a single string of text.
Writing a CRON Expression
There are two core concepts to understanding a CRON expression: field properties and special characters.
Seconds |
Minutes |
Hours |
Day of Month |
Month |
Day of Week |
Year |
|
| Accepted Values |
|
|
|
|
|
|
|
| Special Characters |
|
|
|
|
|
|
|
| Required? | Yes |
Yes |
Yes |
Yes |
Yes |
Yes |
No |
Field Properties
The basic syntax of a CRON expression is a string consisting of six or seven fields separated by white space. Each field represents a different measurement of time and is populated with datetime values, special characters, or a combination of the two.
From left to right, the fields are as follows:
[Seconds] [Minutes] [Hours] [Day of Month]* [Month] [Day of Week]* [Year]**
* The "Day of Month" and "Day of Week" fields are mutually exclusive. Only one of the two fields can be used in a CRON expression; the unused field must be disabled with the special character "?".
** The "Year" field is optional. If the field is unnecessary, it can be omitted.
For example, this string represents a schedule that will run at 6 AM every day:
0 0 6 * * ? *
The accepted datetime values for each field vary according to each measurement of time: the "Seconds" and "Minutes" fields accept a value range of 0-59, the "Hours" field only accepts a value range of 0-23, the "Day of Month" field only accepts a value range of 1-31, and so on.
Special Characters
A variety of special characters can be used alongside datetime values:
, List: Uses 2 or more values to specify a list of discrete values. For example, in the "Hours" field, 9,13,17 means "trigger at 9 AM, 1 PM, and 5 PM".
- Range: Uses a pair of values to define a range. For example, in the "Hours" field, 9-17 means "trigger every hour from 9 AM to 5 PM".
* Wildcard: Used to select all possible values within a field. For example, in the "Minutes" field, * means "trigger every minute".
/ Increments: Uses a pair of values to specify value increments. The first value sets the starting time and the second value sets the increment. For example, in the "Minutes" field, 0/15 means "trigger at 15-minute intervals starting at the beginning of each hour", whereas 10/15 means "trigger at 15-minute intervals starting 10 minutes into each hour".
? No Specific Value: Used to disable either the "Day of Month" field or the "Day of Week" field. ? cannot be used in other fields, and it can only be used once per expression.
L Last: This character has two different meanings depending on the field:
- In the "Day of Month" field,
Lrepresents the last day of the month (e.g., January 31st). - In the "Day of Week" field,
Lallows users to specify a last specific day of the month; for example,2Lmeans "trigger on the last Monday of the month"
W Weekday: Used to specify the weekday (Mon-Fri) that is nearest to a given day within the same month. W can only be used in the "Day of Month" field. For example, if the value was entered as 15W, this means "trigger on the weekday closest to the 15th day of the month". If the 15th is a Saturday, this will trigger on Friday; if the 15th is a Sunday, this will trigger on Monday.
# Nth Day of the Month: Uses a pair of values to specify the "Nth" occurrence of a specific day. # can only be used in the "Day of Week" field. The first value sets the day of the week and the second value sets the "Nth" occurrence. For example, 6#1 means "trigger on the first Friday of the month".
Example Expressions
| Expression | Meaning |
0 0 12 * * ? |
Trigger at 12 PM (noon) every day |
0 15 10 ? * * |
Trigger at 10:15 AM every day |
0 15 10 * * ? |
Trigger at 10:15 AM every day |
0 15 10 * * ? * |
Trigger at 10:15 AM every day |
0 15 10 * * ? 2005 |
Trigger at 10:15 AM every day during the year 2005 |
0 * 14 * * ? |
Trigger every minute starting at 2 PM and ending at 2:59 PM, every day |
0 0/5 14 * * ? |
Trigger every 5 minutes starting at 2 PM and ending at 2:55 PM, every day |
0 0/5 14,18 * * ? |
Trigger every 5 minutes starting at 2 PM and ending at 2:55 PM, AND fire every 5 minutes starting at 6 PM and ending at 6:55 PM, every day |
0 0-5 14 * * ? |
Trigger every minute starting at 2 PM and ending at 2:05 PM, every day |
0 10,44 14 ? 3 WED |
Trigger at 2:10 PM and at 2:44 PM every Wednesday in the month of March |
0 15 10 ? * MON-FRI |
Trigger at 10:15 AM every Monday, Tuesday, Wednesday, Thursday and Friday |
0 15 10 15 * ? |
Trigger at 10:15 AM on the 15th day of every month |
0 15 10 L * ? |
Trigger at 10:15 AM on the last day of every month |
0 15 10 ? * 6L |
Trigger at 10:15 AM on the last Friday of every month |
0 15 10 ? * 6L |
Trigger at 10:15 AM on the last Friday of every month |
0 15 10 ? * 6L 2002-2005 |
Trigger at 10:15 AM on every last Friday of every month during the years 2002, 2003, 2004 and 2005 |
0 15 10 ? * 6#3 |
Trigger at 10:15 AM on the third Friday of every month |
0 0 12 1/5 * ? |
Trigger at 12 PM (noon) every 5 days every month, starting on the first day of the month |
0 11 11 11 11 ? |
Trigger every November 11th at 11:11 AM |
This is how to enter a CRON expression in the FME Flow Scheduling page:
CRON expressions can be tested on www.freeformatter.com