The Scheduler component is a Mule event source that triggers the execution of a flow based on a time-based condition. For example, a Scheduler might create and send a message that will trigger the flow processing every 5 seconds or every day at 12:00 in a given time zone.
Consider the following when adding a Scheduler to your Mule application:
Schedulers use the same timezone as the machine on which Mule is running. However, if an application is running in CloudHub, the Scheduler conforms to the UTC timezone, regardless of the geographic region in which the application is running.
In a Mule runtime engine cluster or multi-worker CloudHub deployment, the Scheduler executes only on the primary node (that is, only in one Mule instance).
<scheduler doc:name="Scheduler">
<scheduling-strategy>
<fixed-frequency frequency="15" timeUnit="SECONDS" />
</scheduling-strategy>
</scheduler>
<!-- One or more processors here. -->
</flow>
The cron expression in this Scheduler triggers the generation of a Mule message in a new execution of the flow every fifteen seconds:
At least one processor must follow the Scheduler. Processors include Mule components and connector operations, such as an HTTP Request operation or Transform Message component. Failure to provide a processor produces a
MuleRuntimeException
and causes the deployment of the Mule application to fail with the following ERROR message in the logs (edited for readability):
The Scheduler elements accept attributes for configuring the execution interval and concurrency.
By default, the Scheduler does not wait for one execution of a given flow to complete before executing another instance of the flow at the configured cadence. You can change this behavior by setting the
disallowConcurrentExecution="true"
attribute directly in the configuration XML.
<flow name="scheduler-disallowConcurrentExecution-ex" >
<scheduler doc:name="Scheduler" disallowConcurrentExecution="true" >
<scheduling-strategy>
<fixed-frequency frequency="10" timeUnit="MILLISECONDS"/>
</scheduling-strategy>
</scheduler>
<!-- processors here -->
</flow>
Each time a Scheduler skips its execution, Mule logs an
Execution skipped
message, for example (edited for readability):
INFO 2022-11-09 15:15:43,082 ...
...scheduler.DefaultSchedulerMessageSource:
Flow 'scheduler-disallowConcurrentExecution-ex' is already running and
'disallowConcurrentExecution' is set to 'true'. Execution skipped.
INFO 2022-11-09 15:15:43,083 ...
...scheduler.DefaultSchedulerMessageSource:
Flow 'scheduler-disallowConcurrentExecution-ex' is already running and
'disallowConcurrentExecution' is set to 'true'. Execution skipped.
<scheduler doc:name="Scheduler" >
<scheduling-strategy >
<fixed-frequency frequency="10" timeUnit="SECONDS" startDelay="10"/>
</scheduling-strategy>
</scheduler>
<scheduler>
<scheduling-strategy>
<cron expression="0 0 12 * * ?" timeZone="America/Los_Angeles"/>
</scheduling-strategy>
</scheduler>
<logger message="my message"/>
</flow>
Cron is a widely used standard for describing time and date information. The Cron Expression (
<cron expression />
scheduling strategy (
<scheduling-strategy >
) is useful for triggering a flow at intervals not available through the Fixed Frequency scheduling strategy.
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. Specify the settings in the following order:
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.
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 month and day-of-the-week fields.
#
: "nth" day of the month. For example,
#3
is the third day of the month.