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