From f267720af4414ecb7f85093cf229008e5c9559a8 Mon Sep 17 00:00:00 2001 From: whyour Date: Mon, 17 Apr 2023 13:36:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E6=9C=8D=E5=8A=A1=E8=BF=90=E8=A1=8C=E9=9D=9E?= =?UTF-8?q?=E7=A6=81=E7=94=A8=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/schedule/addCron.ts | 3 +++ back/services/cron.ts | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/back/schedule/addCron.ts b/back/schedule/addCron.ts index 1b17fd27..c9b4f451 100644 --- a/back/schedule/addCron.ts +++ b/back/schedule/addCron.ts @@ -10,6 +10,9 @@ const addCron = ( ) => { for (const item of call.request.crons) { const { id, schedule, command } = item; + if (scheduleStacks.has(id)) { + scheduleStacks.get(id)?.cancel(); + } scheduleStacks.set( id, nodeSchedule.scheduleJob(id, schedule, async () => { diff --git a/back/services/cron.ts b/back/services/cron.ts index 67652d35..e85cfd0a 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -19,7 +19,7 @@ import cronClient from '../schedule/client'; @Service() export default class CronService { - constructor(@Inject('logger') private logger: winston.Logger) {} + constructor(@Inject('logger') private logger: winston.Logger) { } private isSixCron(cron: Crontab) { const { schedule } = cron; @@ -51,6 +51,9 @@ export default class CronService { const tab = new Crontab({ ...doc, ...payload }); tab.saved = false; const newDoc = await this.updateDb(tab); + if (doc.isDisabled === 1) { + return newDoc; + } if (this.isSixCron(doc)) { await cronClient.delCron([String(newDoc.id)]); } @@ -581,7 +584,7 @@ export default class CronService { this.set_crontab(tabs); const sixCron = tabs.data - .filter((x) => this.isSixCron(x)) + .filter((x) => this.isSixCron(x) && x.isDisabled !== 1) .map((doc) => ({ id: String(doc.id), schedule: doc.schedule!,