From a6fd96e97b49956b3686c97f24e64071b848333f Mon Sep 17 00:00:00 2001 From: whyour Date: Wed, 4 Jan 2023 21:09:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=9A=E6=97=B6=E8=A7=84?= =?UTF-8?q?=E5=88=99=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/cron.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/back/services/cron.ts b/back/services/cron.ts index 65e2339d..7dab67b2 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -32,7 +32,7 @@ export default class CronService { const tab = new Crontab(payload); tab.saved = false; const doc = await this.insert(tab); - await this.set_crontab(this.isSixCron(doc)); + await this.set_crontab(); return doc; } @@ -43,7 +43,7 @@ export default class CronService { public async update(payload: Crontab): Promise { payload.saved = false; const newDoc = await this.updateDb(payload); - await this.set_crontab(this.isSixCron(newDoc)); + await this.set_crontab(); return newDoc; } @@ -82,7 +82,7 @@ export default class CronService { public async remove(ids: number[]) { await CrontabModel.destroy({ where: { id: ids } }); - await this.set_crontab(true); + await this.set_crontab(); } public async pin(ids: number[]) { @@ -409,12 +409,12 @@ export default class CronService { public async disabled(ids: number[]) { await CrontabModel.update({ isDisabled: 1 }, { where: { id: ids } }); - await this.set_crontab(true); + await this.set_crontab(); } public async enabled(ids: number[]) { await CrontabModel.update({ isDisabled: 0 }, { where: { id: ids } }); - await this.set_crontab(true); + await this.set_crontab(); } public async log(id: number) { @@ -530,7 +530,7 @@ export default class CronService { return crontab_job_string; } - private async set_crontab(needReloadSchedule: boolean = false) { + private async set_crontab() { const tabs = await this.crontabs(); var crontab_string = ''; tabs.data.forEach((tab) => { @@ -553,9 +553,7 @@ export default class CronService { fs.writeFileSync(config.crontabFile, crontab_string); execSync(`crontab ${config.crontabFile}`); - if (needReloadSchedule) { - exec(`pm2 reload schedule`); - } + exec(`pm2 reload schedule`); await CrontabModel.update({ saved: true }, { where: {} }); }