Javascript执行定时任务
node-schedule 用于基于时间的调度,toad-scheduler 用于基于间隔的调度。
node-scheduler
Node Schedule is a flexible cron-like and not-cron-like job scheduler for Node.js. It allows you to schedule jobs (arbitrary functions) for execution at specific dates, with optional recurrence rules. It only uses a single timer at any given time (rather than reevaluating upcoming jobs every second/minute).
Node 6+ is supported.
使用说明:
second (0-59)
minute (0-59)
hour (0-23)
date (1-31)
month (0-11)
year
dayOfWeek (0-6) Starting with Sunday
tz
使用方法:
每个小时的第30分钟执行
1 |
|
每周日下午 2:30 记录一条消息:
1 |
|
toad-scheduler
In-memory TypeScript job scheduler that repeatedly executes given tasks within specified intervals of time (e. g. “each 20 seconds”). Cron syntax is also supported in case you need it.
Node.js 12+ and modern browsers are supported
使用方法
1 |
|
参考资料
https://github.com/node-schedule/node-schedule
https://github.com/kibertoad/toad-scheduler