All Products
Search
Document Center

OpenSearch:cron field in ScheduledTask

Last Updated:Oct 21, 2022

Description

The cron field in ScheduledTask defines the scheduling rule of a scheduled task. The scheduled task is scheduled by using the node-schedule component. The format of the scheduling rule must be the same as the cron format of the component.

Example

Note

*/5 * * * * *

Define a scheduling rule

s  i  h  d  m  w
-  -  -  -  -  -
|  |  |  |  |  |
|  |  |  |  |  +-- The day in a week. Valid values: [0,7]. Both 0 and 7 indicate Sunday.
|  |  |  |  +----- The sequence number of the month in a year. Valid values: [1,12].
|  |  |  +-------- The sequence number of the day in the month. Valid values: [1,31].
|  |  +----------- The hour in 24-hour clock time. Valid values: [0, 23].
| + -------------- The minute. Valid values: [0,59].
+----------------- Optional. The second. Valid values: [0,59].
  • s indicates the second. i indicates the minute. h indicates the hour. d indicates the sequence number of the day in the month. m indicates the sequence number of the month in the year. w indicates the sequence number of the day in the week. In most cases, s is not set.

  • If the value is an asterisk (*), the scheduled task is run at each interval. For example, If you set i to an asterisk (*), the scheduled task is run every minute. If you set h to an asterisk (*), the scheduled task is run every hour.

  • If the value is in the format of a-b, the scheduled task is run in the specified time period. For example, if you set i to a-b, the scheduled task is run from the a minute to the b minute. If you set h to a-b, the scheduled task is run from the a hour to the b hour.

  • If the value is in the format of */n, the scheduled task is run at a specified interval. For example, if you set i to */n, the scheduled task is run every n minutes. If you set h to */n, the scheduled task is run every n hours.

  • If you specify multiple values, the scheduled task is run at each point of time. For example, if you set i to "a,b,c", the scheduled task is run at the a, b, and c minutes. If you set h to "a,b,c", the scheduled task is run at the a, b, and c hours.

For more information, see node-schedule.