Cron is a widely used standard for describing time and date information.
The Scheduler keeps track of every second and creates a Mule event when the
Quartz Cron expression matches your time-date setting. You can trigger the event
just once or at regular intervals.
A date-time expression consists of six required settings and can include the
optional year setting. You specify the settings in the following order:
-
Seconds (0-59)
-
Minutes (0-59)
-
Hours (0-23)
-
Day of month (1-31)
-
Month (1-12 or JAN-DEC)
-
Day of the week (1-7 or SUN-SAT)
-
Year (empty or a 4-digit year between 1970-2099, for example, 2019)
The Scheduler supports Quartz Cron expressions. Here are a few examples:
| Expression |
Behavior |
1/2 * * * * ?
|
Run every 2 seconds of the day, every day. |
0 15 10 ? * *
|
Run at 10:15 a.m., every day. 0 15 10 * * ? * and
0 15 10 * * ? produce the same effect. |
0 15 10 * * ? 2019
|
Run at 10:15 a.m., every day during the year 2019. |
0 * 14 * * ?
|
Run every minute starting at 2pm and ending at 2:59pm, every day. |
0 0/5 14 * * ?
|
Run every 5 minutes starting at 2pm and ending at 2:55pm, every day |
1 1 1 1,7 * ?
|
Run the first second of the first minute of the first hour, on the first and seventh day, every month. |
Note that the Scheduler component also supports Quartz Scheduler special characters:
-
*: All values.
-
?: No specific value.
-
-: Range of values, for example, 1-3.
-
,: Additional values, for example, 1,7.
-
/: Incremental values, for example, 1/7.
-
L: Last day of the week or month, or last specific day of the month
(such as 6L for the last Saturday of the month).
-
W: Weekday, which is valid in the day-of-month field and must follow a specific day. For example, 15W for the weekday nearest to the 15th of the month.
-
#: Nth day of the month. For example, #3 is the third day of the month.
This example logs the message "hello" every second:
<flow name="cronFlow" doc:id="ae257a5d-6b4f-4006-80c8-e7c76d2f67a0" >
<scheduler doc:name="Scheduler" doc:id="e7b68ccb-c6d8-4567-87af-aa7904a50359" >
<scheduling-strategy >
<cron expression="* * * * * ?" timeZone="America/Los_Angeles"/>
</scheduling-strategy>
</scheduler>
<logger level="INFO" doc:name="Logger" doc:id="e2626dbb-54a9-4791-8ffa-b7c9a23e88a1" message='"hello"'/>
</flow>
Note that there are a number of free online tools that can help you build Cron
expressions.
Time Zones (timeZone)
For Cron configurations, Java timeZone values are supported. You should avoid
the Java abbreviations, such as PST and AGT, and instead use the full-name
Java equivalents, such as America/Los_Angeles and
America/Argentina/Buenos_Aires.