schedule.js 638 B

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * 计划任务调度器。
  3. *
  4. * https://github.com/node-schedule/node-schedule
  5. *
  6. * author: Sand
  7. * since: 2016/11/28
  8. */
  9. "use strict";
  10. let nodeSchedule = require('node-schedule');
  11. let log = require("../../util/log.js");
  12. class Schedule {
  13. constructor(){
  14. }
  15. static cronSchedule(cronExp, handler){
  16. log.info('Job scheduled by cron express: ' + cronExp);
  17. return nodeSchedule.scheduleJob(cronExp, handler);
  18. }
  19. static dateSchedule(date, handler){
  20. log.info('Job scheduled at ' + date.toUTCString());
  21. return nodeSchedule.scheduleJob(date, handler);
  22. }
  23. }
  24. module.exports = Schedule;