Nuxeo Server

Scheduling Periodic Events

Updated: December 5, 2017 Page Information Edit on GitHub

The Scheduler Service is a Nuxeo Platform service to schedule events at periodic times. This is the best way in Nuxeo Platform to execute things every night, every hour, every five minutes, or at whatever granularity you require.

Scheduler Contribution

To schedule an event, you contribute a <schedule> to the schedule extension point of the SchedulerService component.

A schedule is defined by:

  • id: an identifier.
  • username: the user under which the event should be executed.
  • event: the identifier of the event to execute.
  • eventCategory: the event category to use.
  • cronExpression: an expression to specify the schedule.

The id is used for informational purposes and programmatic unregistration.

If the username is missing, the event is executed as a system user, otherwise as that user. No password is needed: the login is done internally.

The event specifies the event to execute. See the section about Events and Listeners for more.

The eventCategory is also used to specify the event, but usually it can be skipped.

The cronExpression is described in the following section.

Here is an example contribution:

<?xml version="1.0"?>
<component name="com.example.nuxeo.schedule.monthly_stuff">
  <extension target="org.nuxeo.ecm.core.scheduler.SchedulerService"
      point="schedule">
    <schedule id="monthly_stuff">
      <eventId>doStuff</eventId>
      <eventCategory>default</eventCategory>
      <!-- Every first of the month at 3am -->
      <cronExpression>0 0 3 1 * ?</cronExpression>
    </schedule>
  </extension>
</component>

Cron Expression

A Scheduler cron expression is similar to a Unix cron expression, except that it has an additional seconds field (that isn't needed in Unix which doesn't need this kind of precision).

The expression is a sequence of 6 or 7 fields. Each field can hold a number or a wildcard, or in complex cases a sequence of numbers or an additional increment specification. The fields and their allowed values are:

seconds minutes hours day of month month day of week year
0-59 0-59 0-23 1-31 1-12 1-7 or SUN-SAT optional

A star (*) can be used to mean "all values". A question mark (?) can be used to mean "no specific value" and is allowed for one (but not both) of the day of month and day of week fields.

Note that in the day of week, 1 stands for Sunday, 2 for Monday, 3 for Tuesday, etc. For clarity it's best to use SUN, MON, TUE, etc.

A range of values can be specified using a dash, for instance 1-6 for the months field or MON-WED for the day of week field.

Several values can be specified by separating them with commas, for instance 0,15,30,45 for the minutes field.

Repetitions can be specified using a slash followed by an increment, for instance 0/15 means start at 0 and repeat every 15. This example means the same as the one above.

There's actually more but rarely used functionality; the Scheduler's full cron expression syntax is described in detail in the Quartz CronExpression Javadoc and in the CronTrigger Tutorial.

Cron Expression Examples

Every first of the month at 3:15am:

0 15 3 1 * ?

At 3:15am every day:

0 15 3 * * ?

Every minute starting at 2pm and ending at 2:15pm, every day:

0 0-15 14 * * ?

At 3:15am every Monday, Tuesday, Wednesday, Thursday and Friday:

0 15 3 ? * MON-FRI

At 3:15a, every 5 days every month, starting on the first day of the month:

0 15 3 1/5 * ?

Automation

When using the Scheduler Service to trigger Automation Chains through Event Listener and Event Handler, the Core Session cannot be retrieved and cannot be set within the Operation Context (Core Session is not found).

If the need is to execute operations needing an operation context session, the first operation of the chain should be LoginAs Operation. It will create a new authenticated session and set the Automation context session accordingly.

7 days ago Manon Lumeau add tags for doc days
a month ago manonlumeau Added content-review-lts2017 label
2 months ago manonlumeau NXDOC-1346-FT review screenshot
2 years ago Vladimir Pasquier 17 | dding warning info related to Automation usage for Schedule
2 years ago Solen Guitter 16 | Update table of contents look
3 years ago Solen Guitter 15 | Remove 5.4 reference
4 years ago Solen Guitter 13
4 years ago Solen Guitter 14 | Added link to the explorer
4 years ago Solen Guitter 12
4 years ago Julien Carsique 11
4 years ago Julien Carsique 10
4 years ago Florent Guillaume 9
4 years ago Thibaud Arguillere 8
5 years ago Solen Guitter 7 | Added TOC and a note about component name change
5 years ago Damien Metzler 6
7 years ago Florent Guillaume 4
7 years ago Florent Guillaume 5 | Migrated to Confluence 4.0
7 years ago Solen Guitter 3
7 years ago Solen Guitter 2
7 years ago Florent Guillaume 1
History: Created by Florent Guillaume