From 42dc27addf9d7c2187f918e9ff6bbc003fe39770 Mon Sep 17 00:00:00 2001 From: whyour Date: Sat, 6 Nov 2021 00:50:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=BB=E5=8A=A1=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E7=BB=93=E6=9D=9F=E6=97=B6=E9=97=B4=E5=B1=95=E7=A4=BA?= 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 5644a227..08d943e1 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -225,7 +225,9 @@ export default class CronService { const str = err ? `\n${err}` : ''; fs.appendFileSync( `${doc.log_path}`, - `${str}\n## 执行结束... ${new Date().toLocaleString()} `, + `${str}\n## 执行结束... ${new Date() + .toLocaleString('zh', { hour12: false }) + .replace(' 24:', ' 00:')} `, ); } } @@ -305,6 +307,17 @@ export default class CronService { fs.appendFileSync(`${log_path}`, `${JSON.stringify(err)}`); } }); + + cp.on('exit', (code, signal) => { + this.logger.info( + `${command} pid: ${cp.pid} exit ${code} signal ${signal}`, + ); + this.cronDb.update( + { _id }, + { $set: { status: CrontabStatus.idle }, $unset: { pid: true } }, + ); + resolve(); + }); cp.on('close', (code) => { this.logger.info(`${command} pid: ${cp.pid} closed ${code}`); this.cronDb.update(