<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>
Scheduler Endpoint (Trigger)
Standard Support for Mule 4.1 ended on November 2, 2020, and this version of Mule reached its End of Life on November 2, 2022, when Extended Support ended. Deployments of new applications to CloudHub that use this version of Mule are no longer allowed. Only in-place updates to applications are permitted. MuleSoft recommends that you upgrade to the latest version of Mule 4 that is in Standard Support so that your applications run with the latest fixes and security enhancements. |
The Scheduler component enables you to trigger a flow when a time-based condition is met. You can configure it to be triggered at a regular interval or give it a more flexible cron expression. For example, a Scheduler might trigger an event to start a flow every 5 seconds.
Schedulers follow the timezone used by the machine where the Mule runtime is running. If an application is running in CloudHub, the timezone that the Scheduler conforms to corresponds to the region in which the CloudHub worker is running.
A Scheduler component can trigger only one flow at any given time, and if a flow is executing, the flow won’t trigger again until it finishes processing. If back-pressure is triggered because no resources are available at the time of the trigger, that trigger is skipped.
Note that in a Mule runtime cluster or multi-worker CloudHub deployment, the Scheduler runs (or triggers) only on the primary node (that is, only in one Mule runtime).
There are several example projects in Anypoint Exchange that you can open in Anypoint Studio to learn more about how to use the Scheduler component:
-
Data Sync Using Watermarking and Batch
-
Import Contacts into Microsoft Dynamics CRM
-
Import Leads into Salesforce
-
Importing a CSV File into mongoDB
-
Importing an Email Attachment Using the IMAP Connector
-
Salesforce to MySQL Database Using Batch Processing
-
Sending a CSV File Through Email Using SMTP
To download and open an example project while you are in Anypoint Studio, click the Exchange icon in the upper-left corner. Then, in the window that opens, log into Anypoint Exchange and search on the name of the project.
Fixed Frequency
You can use the following parameters to set a Scheduler to trigger a flow at a regular intervals.
Attribute | Description | Default |
---|---|---|
Frequency |
The frequency at which the Scheduler triggers the flow. You select the unit of time in the Time unit field. Setting the value to |
1000 |
Start Delay |
The amount of time to wait before triggering the flow for the first time after the application is started. This value is expressed in the same unit of time as the frequency. |
0 |
Time Unit |
The time unit for the values of Frequency and Start Delay. The possible values are: MILLISECONDS, SECONDS, MINUTES, HOURS, DAYS |
MILLISECONDS |
Cron Expressions
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 |
---|---|
|
Run every 2 seconds of the day, every day. |
|
Run at 10:15 a.m., every day. |
|
Run at 10:15 a.m., every day during the year 2019. |
|
Run every minute starting at 2pm and ending at 2:59pm, every day. |
|
Run every 5 minutes starting at 2pm and ending at 2:55pm, every day |
|
Run the first day of January and the first day of June, every year (in the first second of the first minute of the first hour) |
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 as6L
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.
This example logs the message "hello" every second:
Note that there are a number of free online tools that can help you build Cron expressions.
Debugging
In the Studio Debug Mode view, the Mule app disables the triggering of events. You can instead execute the Scheduler component when debugging by clicking the green arrow icon that appears at the bottom of the component.