diff --git a/back/schedule.ts b/back/schedule.ts index 1fdad0db..a6f4f601 100644 --- a/back/schedule.ts +++ b/back/schedule.ts @@ -1,13 +1,15 @@ import schedule from 'node-schedule'; -import DataStore from 'nedb'; -import config from './config'; import { exec } from 'child_process'; import Logger from './loaders/logger'; - -const db = new DataStore({ filename: config.cronDbFile, autoload: true }); +import { Container } from 'typedi'; +import CronService from './services/cron'; const run = async () => { - db.find({}) + const cronService = Container.get(CronService); + const cronDb = cronService.getDb(); + + cronDb + .find({}) .sort({ created: 1 }) .exec((err, docs) => { if (err) { diff --git a/back/services/cron.ts b/back/services/cron.ts index 61559186..81dc6f23 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -190,17 +190,20 @@ export default class CronService { const tabs = await this.crontabs(); var crontab_string = ''; tabs.forEach((tab) => { - if (tab.status === CrontabStatus.disabled) { - crontab_string += '# '; - crontab_string += tab.schedule; - crontab_string += ' '; - crontab_string += this.make_command(tab); - crontab_string += '\n'; - } else { - crontab_string += tab.schedule; - crontab_string += ' '; - crontab_string += this.make_command(tab); - crontab_string += '\n'; + const _schedule = tab.schedule && tab.schedule.split(' '); + if (_schedule && _schedule.length === 5) { + if (tab.status === CrontabStatus.disabled) { + crontab_string += '# '; + crontab_string += tab.schedule; + crontab_string += ' '; + crontab_string += this.make_command(tab); + crontab_string += '\n'; + } else { + crontab_string += tab.schedule; + crontab_string += ' '; + crontab_string += this.make_command(tab); + crontab_string += '\n'; + } } }); @@ -208,7 +211,7 @@ export default class CronService { fs.writeFileSync(config.crontabFile, crontab_string); execSync(`crontab ${config.crontabFile}`); - execSync(`pm2 restart schedule`); + exec(`pm2 restart schedule`); this.cronDb.update({}, { $set: { saved: true } }, { multi: true }); } diff --git a/docker/Dockerfile b/docker/Dockerfile index 54c0bdb0..2796a620 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -36,6 +36,7 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && rm -rf /root/.npm \ && yarn install --network-timeout 100000 \ && yarn build \ + && yarn build-back \ && yarn install --production --network-timeout 100000 \ && yarn cache clean ENTRYPOINT ["./docker/docker-entrypoint.sh"] \ No newline at end of file diff --git a/shell/update.sh b/shell/update.sh index 37a25146..b192da10 100755 --- a/shell/update.sh +++ b/shell/update.sh @@ -321,16 +321,17 @@ restart_qinglong() { echo -e "重新编译青龙...\n" yarn install --network-timeout 1000000000 || yarn install --registry=https://registry.npm.taobao.org --network-timeout 1000000000 yarn build + yarn build-back yarn cache clean echo -e "重新编译青龙完成...\n" echo -e "重启青龙面板...\n" - pm2 restart panel 2>/dev/null || pm2 start npm -n panel -- run panel + pm2 restart panel 2>/dev/null || pm2 start $dir_root/build/app.js -n panel nginx -s reload 2>/dev/null || nginx -c /etc/nginx/nginx.conf echo -e "重启面板完成...\n" echo -e "重启定时任务...\n" - pm2 restart schedule 2>/dev/null || pm2 start npm -n schedule -- run schedule + pm2 restart schedule 2>/dev/null || pm2 start $dir_root/build/schedule.js -n schedule echo -e "重启定时完成...\n" fi }