修复定时任务列表创建

This commit is contained in:
whyour 2021-05-03 23:04:42 +08:00
parent 748d00ae45
commit eb9217d46e
2 changed files with 17 additions and 14 deletions

View File

@ -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);
});

View File

@ -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';
}
});