From eb9217d46ef76b307e97ac05ac03a1eb658fbea5 Mon Sep 17 00:00:00 2001 From: whyour Date: Mon, 3 May 2021 23:04:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E5=88=97=E8=A1=A8=E5=88=9B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/schedule.ts | 7 ++++++- back/services/cron.ts | 24 +++++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/back/schedule.ts b/back/schedule.ts index a6f4f601..07ff6bbd 100644 --- a/back/schedule.ts +++ b/back/schedule.ts @@ -3,6 +3,7 @@ import { exec } from 'child_process'; import Logger from './loaders/logger'; import { Container } from 'typedi'; import CronService from './services/cron'; +import { CrontabStatus } from './data/cron'; const run = async () => { const cronService = Container.get(CronService); @@ -21,7 +22,11 @@ const run = async () => { for (let i = 0; i < docs.length; i++) { const task = docs[i]; const _schedule = task.schedule && task.schedule.split(' '); - if (_schedule && _schedule.length > 5) { + if ( + _schedule && + _schedule.length > 5 && + task.status !== CrontabStatus.disabled + ) { schedule.scheduleJob(task.schedule, function () { exec(task.command); }); diff --git a/back/services/cron.ts b/back/services/cron.ts index 81dc6f23..de49f013 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -191,19 +191,17 @@ export default class CronService { var crontab_string = ''; tabs.forEach((tab) => { 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'; - } + if (tab.status === CrontabStatus.disabled || _schedule.length !== 5) { + 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'; } });