index.js 601 B

1234567891011121314151617181920
  1. const cron = require('node-cron');
  2. const settings = [
  3. ['fetch-meta', '* * * * *', require('./fetch-meta')], // 每个小时跑一遍,ai自动生成标题和文案
  4. ]
  5. settings.forEach(setting => {
  6. let [name, schedule, job] = setting;
  7. if (!job.run) throw new Error(`Job [${name}] has no run() function`);
  8. console.log(`[${name}] run@'${schedule}' installed!`);
  9. cron.schedule(schedule, () => {
  10. let date = new Date().toLocaleString();
  11. console.log(`[${name}]@'${schedule}' running @ ${date}`);
  12. if (job.run) {
  13. job.run().then(console.log).catch(console.error);
  14. }
  15. })
  16. })