From 57fd8f378c3550423078a331844f41c763e9c2a5 Mon Sep 17 00:00:00 2001 From: whyour Date: Sun, 30 Jan 2022 10:11:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E5=94=AF=E4=B8=80=E9=94=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/data/cron.ts | 14 ++++++++++---- back/services/cron.ts | 5 +++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/back/data/cron.ts b/back/data/cron.ts index 56f0ec81..d6f829cf 100644 --- a/back/data/cron.ts +++ b/back/data/cron.ts @@ -49,12 +49,18 @@ export enum CrontabStatus { interface CronInstance extends Model, Crontab {} export const CrontabModel = sequelize.define('Crontab', { - name: DataTypes.STRING, - command: { - unique: 'command', + name: { + unique: 'compositeIndex', + type: DataTypes.STRING, + }, + command: { + unique: 'compositeIndex', + type: DataTypes.STRING, + }, + schedule: { + unique: 'compositeIndex', type: DataTypes.STRING, }, - schedule: DataTypes.STRING, timestamp: DataTypes.STRING, saved: DataTypes.BOOLEAN, status: DataTypes.NUMBER, diff --git a/back/services/cron.ts b/back/services/cron.ts index aaa91b73..fa4f445b 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -5,7 +5,7 @@ import { Crontab, CrontabModel, CrontabStatus } from '../data/cron'; import { exec, execSync, spawn } from 'child_process'; import fs from 'fs'; import cron_parser from 'cron-parser'; -import { getFileContentByName, concurrentRun } from '../config/util'; +import { getFileContentByName, concurrentRun, fileExist } from '../config/util'; import { promises, existsSync } from 'fs'; import { promisify } from 'util'; import { Op } from 'sequelize'; @@ -194,7 +194,8 @@ export default class CronService { } } const err = await this.killTask(doc.command); - if (doc.log_path) { + const logFileExist = await fileExist(doc.log_path); + if (doc.log_path && logFileExist) { const str = err ? `\n${err}` : ''; fs.appendFileSync( `${doc.log_path}`,