schedule.js 1019 B

12345678910111213141516171819202122232425262728
  1. 'use strict'
  2. require('./config.js');
  3. let child_process = require('child_process');
  4. let CronJob = require('cron').CronJob;
  5. let job = new CronJob({
  6. cronTime: '0 0,15 * * * *',
  7. onTick: runAnalysis,
  8. start: false,
  9. timeZone: "Asia/Shanghai"
  10. });
  11. job.start();
  12. runAnalysis();
  13. function runAnalysis(){
  14. let date = new Date();
  15. let startTime = date.getTime();
  16. LOGGER.info('--------------------------------------------------------------');
  17. LOGGER.info('Analysis task start : ' + date);
  18. LOGGER.info('--------------------------------------------------------------');
  19. let task = child_process.fork('./analysis.js');
  20. task.on('close',function(){
  21. date = new Date();
  22. let runThrough = Math.floor((date.getTime()-startTime)/1000);
  23. LOGGER.info('--------------------------------------------------------------');
  24. LOGGER.info(`Analysis task finished in [ ${runThrough}s ]`);
  25. LOGGER.info('--------------------------------------------------------------');
  26. })
  27. }