| 1234567891011121314151617181920 |
- const cron = require('node-cron');
- const settings = [
- ['fetch-meta', '* * * * *', 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);
- }
- })
- })
|