index.js 680 B

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