node-schedule cron作业规则

时间:2018-03-13 11:54:46

标签: node.js cron scheduled-tasks

我根据项目要求创建了少量cron格式,并且不确定它们是否都正确。我测试了几分钟和每小时,他们工作正常,但不确定其他人。因此,如果我在任何地方错了,我可以在下面分享:

           case "yearly":
                interval = '0 0 0 1 1 *'; //start of the year, 1st of Jan every year
                break;
            case "monthly":
                interval = '0 0 0 1 * *'; //beginning of month, 1st of every month
                break;
            case "weekly":
                interval = '0 0 0 * * 7'; //every week on Sunday
                break;
            case "daily":
                interval = '0 0 * * *'; //every day at 12 AM
                break;
            case "hourly":
                interval = '0 0 1 * * *'; //every hour
                break;
            default:
                interval = '* * * * *'; //every minute
                break;

谢谢!

1 个答案:

答案 0 :(得分:0)

假设您指的是https://www.npmjs.com/package/node-schedule

*    *    *    *    *    *
┬    ┬    ┬    ┬    ┬    ┬
│    │    │    │    │    │
│    │    │    │    │    └ day of week (0 - 7) (0 or 7 is Sun)
│    │    │    │    └───── month (1 - 12)
│    │    │    └────────── day of month (1 - 31)
│    │    └─────────────── hour (0 - 23)
│    └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, OPTIONAL)

每小时仅在凌晨1点0分0秒工作一次