ScheduledTask cron rules

更新时间:
复制 MD 格式

The cron field in ScheduledTask defines the scheduling rule for a scheduled task. OpenSearch uses the node-schedule component to run scheduled tasks, so the scheduling rule must follow the cron format that node-schedule accepts.

Field reference

A cron expression contains five or six space-separated fields, listed left to right:

second  minute  hour  day-of-month  month  day-of-week
  s       i       h        d           m        w
The second field is optional. In most cases, omit it and write a five-field expression.
FieldAbbreviationValid valuesRequired
Seconds0–59No
Minutei0–59Yes
Hourh0–23 (24-hour clock)Yes
Day of monthd1–31Yes
Monthm1–12Yes
Day of weekw0–7 (0 and 7 both mean Sunday)Yes

Special characters

CharacterMeaningExample
*Every unit — matches all valid values* * * * * runs every minute
a-bRange — runs during the specified interval9-17 in the hour field runs every hour from 9 AM to 5 PM
*/nStep — runs every n units*/5 in the minute field runs every 5 minutes
a,b,cList — runs at each specified value1,15 in the day-of-month field runs on the 1st and 15th of each month

Examples

ExpressionRuns
* * * * *Every minute
0 * * * *Every hour, on the hour
0 9 * * *Every day at 9:00 AM
0 9 * * 1Every Monday at 9:00 AM
0 9 1 * *On the 1st of every month at 9:00 AM
*/5 * * * * *Every 5 seconds (six-field expression with second field)
0 9-17 * * 1-5Every hour from 9 AM to 5 PM, Monday through Friday

What's next