From 7092be97ebfd44f7989415c5351472f7c44d9526 Mon Sep 17 00:00:00 2001 From: hanhh <18330117883@163.com> Date: Fri, 20 Aug 2021 10:59:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=8B=E5=8A=A8=E8=BF=90=E8=A1=8C=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=B7=BB=E5=8A=A0=E9=94=99=E8=AF=AF=E6=8D=95=E8=8E=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/cron.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/back/services/cron.ts b/back/services/cron.ts index fc41d3f0..ae00e229 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -232,7 +232,7 @@ export default class CronService { return; } - let { _id, command } = cron; + let { _id, command, log_path } = cron; this.logger.silly('Running job'); this.logger.silly('ID: ' + _id); @@ -251,7 +251,20 @@ export default class CronService { { _id }, { $set: { status: CrontabStatus.running, pid: cp.pid } }, ); + cp.stderr.on('data', (data) => { + this.logger.info(`stderr: ${data}`); + if (log_path) { + fs.appendFileSync(`${log_path}`, `${data}`); + } + }); + cp.on('error', (err) => { + this.logger.info(`err: ${err}`); + if (log_path) { + fs.appendFileSync(`${log_path}`, `${JSON.stringify(err)}`); + } + }); cp.on('close', (code) => { + this.logger.info(`${command} pid: ${cp.pid} closed ${code}`); this.cronDb.update( { _id }, { $set: { status: CrontabStatus.idle }, $unset: { pid: true } },