Contact Us 1-800-596-4880

Scheduler Endpoint (Trigger)

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.

Consider the following when you implement a Scheduler in 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.

  • The disallowConcurrentExecution property enables you to prevent the Scheduler from re-triggering a flow until it finishes processing. See <scheduler> Properties.

  • If back-pressure occurs because no resources are available at the time of the scheduled trigger, Mule skips the trigger.

  • In a Mule runtime engine cluster or multi-worker CloudHub deployment, the Scheduler runs (or triggers the flow) only on the primary node (that is, only in one Mule instance).

Example Projects

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 0 or a negative value causes the default value to be used.

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:

  1. Seconds (0-59)

  2. Minutes (0-59)

  3. Hours (0-23)

  4. Day of month (1-31)

  5. Month (1-12 or JAN-DEC)

  6. Day of the week (1-7 or SUN-SAT)

  7. 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 month and day-of-the-week fields.

  • #: Nth day of the month. For example, #3 is the third day of the month.

See CronExpression for more information.

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.

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.