From f0f2c6b5377f13e90bde31210a326ba109e287ea Mon Sep 17 00:00:00 2001 From: whyour Date: Sat, 19 Feb 2022 22:54:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9D=80=E6=AD=BB=E8=BF=9B?= =?UTF-8?q?=E7=A8=8B=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/cron.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/back/services/cron.ts b/back/services/cron.ts index fa4f445b..4c8d1a08 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -226,15 +226,18 @@ export default class CronService { const killLogs = []; if (pids && pids.length > 0) { // node 执行脚本时还会有10个子进程,但是ps -ef中不存在,所以截取前三个 - pids = pids.slice(0, 3); for (const id of pids) { const c = `kill -9 ${id.slice(1)}`; - const { stdout, stderr } = await execAsync(c); - if (stderr) { - killLogs.push(stderr); - } - if (stdout) { - killLogs.push(stdout); + try { + const { stdout, stderr } = await execAsync(c); + if (stderr) { + killLogs.push(stderr); + } + if (stdout) { + killLogs.push(stdout); + } + } catch (error: any) { + killLogs.push(error.message); } } }