修改任务队列执行日志

This commit is contained in:
whyour
2023-10-06 02:34:40 +08:00
parent 9d55cb108c
commit ec5b885476
16 changed files with 162 additions and 78 deletions
+4 -6
View File
@@ -2,11 +2,10 @@ import { spawn } from 'cross-spawn';
import taskLimit from './pLimit';
import Logger from '../loaders/logger';
export function runCron(cmd: string): Promise<number> {
return taskLimit.runWithCpuLimit(() => {
export function runCron(cmd: string, options?: { schedule: string; extraSchedules: Array<{ schedule: string }>; name: string }): Promise<number | void> {
return taskLimit.runWithCronLimit(() => {
return new Promise(async (resolve: any) => {
Logger.info(`[schedule][开始执行任务] 运行命令: ${cmd}`);
Logger.info(`[schedule][开始执行任务] 参数 ${JSON.stringify({ ...options, command: cmd })}`);
const cp = spawn(cmd, { shell: '/bin/bash' });
cp.stderr.on('data', (data) => {
@@ -25,8 +24,7 @@ export function runCron(cmd: string): Promise<number> {
});
cp.on('close', async (code) => {
Logger.info(`[schedule][任务退出] ${cmd} 进程id: ${cp.pid} 退出, 退出码 ${code}`);
resolve();
resolve({ ...options, command: cmd, pid: cp.pid, code });
});
});
});