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 wThe second field is optional. In most cases, omit it and write a five-field expression.| Field | Abbreviation | Valid values | Required |
|---|---|---|---|
| Second | s | 0–59 | No |
| Minute | i | 0–59 | Yes |
| Hour | h | 0–23 (24-hour clock) | Yes |
| Day of month | d | 1–31 | Yes |
| Month | m | 1–12 | Yes |
| Day of week | w | 0–7 (0 and 7 both mean Sunday) | Yes |
Special characters
| Character | Meaning | Example |
|---|---|---|
* | Every unit — matches all valid values | * * * * * runs every minute |
a-b | Range — runs during the specified interval | 9-17 in the hour field runs every hour from 9 AM to 5 PM |
*/n | Step — runs every n units | */5 in the minute field runs every 5 minutes |
a,b,c | List — runs at each specified value | 1,15 in the day-of-month field runs on the 1st and 15th of each month |
Examples
| Expression | Runs |
|---|---|
* * * * * | Every minute |
0 * * * * | Every hour, on the hour |
0 9 * * * | Every day at 9:00 AM |
0 9 * * 1 | Every 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-5 | Every hour from 9 AM to 5 PM, Monday through Friday |
What's next
For the full node-schedule cron syntax, see the node-schedule documentation.
该文章对您有帮助吗?