修复禁用任务后git_pull会重新添加

This commit is contained in:
whyour
2021-04-04 19:13:44 +08:00
parent 78ab74fe1b
commit a0c5b33239
2 changed files with 23 additions and 6 deletions
+15 -3
View File
@@ -82,7 +82,7 @@ export default class CronService {
}
public async run(_id: string) {
this.cronDb.find({ _id }).exec((err, docs) => {
this.cronDb.find({ _id }).exec((err, docs: Crontab[]) => {
let res = docs[0];
this.logger.silly('Running job');
@@ -92,7 +92,13 @@ export default class CronService {
let logFile = `${config.manualLogPath}${res._id}.log`;
fs.writeFileSync(logFile, `${new Date().toString()}\n\n`);
const cmd = spawn(`${res.command} now`, { shell: true });
let cmdStr = res.command;
if (res.command.startsWith('js')) {
cmdStr = `${res.command} now`;
} else if (/&& (.*) >>/.test(res.command)) {
cmdStr = res.command.match(/&& (.*) >>/)[1];
}
const cmd = spawn(cmdStr, { shell: true });
this.cronDb.update({ _id }, { $set: { status: CrontabStatus.running } });
@@ -141,7 +147,13 @@ export default class CronService {
const tabs = await this.crontabs();
var crontab_string = '';
tabs.forEach((tab) => {
if (tab.status !== CrontabStatus.disabled) {
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);