mirror of
				https://github.com/whyour/qinglong.git
				synced 2025-11-04 20:06:08 +08:00 
			
		
		
		
	执行任务增加结束日志
This commit is contained in:
		
							parent
							
								
									a48d100b2d
								
							
						
					
					
						commit
						7414a9d33d
					
				| 
						 | 
				
			
			@ -431,7 +431,7 @@ export default class CronService {
 | 
			
		|||
        }
 | 
			
		||||
 | 
			
		||||
        this.logger.info(
 | 
			
		||||
          `[panel][开始执行任务] 参数 ${JSON.stringify(params)}`,
 | 
			
		||||
          `[panel][开始执行任务] 参数: ${JSON.stringify(params)}`,
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        let { id, command, log_path } = cron;
 | 
			
		||||
| 
						 | 
				
			
			@ -459,13 +459,28 @@ export default class CronService {
 | 
			
		|||
          await fs.appendFile(absolutePath, data.toString());
 | 
			
		||||
        });
 | 
			
		||||
        cp.stderr.on('data', async (data) => {
 | 
			
		||||
          this.logger.info(
 | 
			
		||||
            '[panel][执行任务失败] 命令: %s, 错误信息: %j',
 | 
			
		||||
            command,
 | 
			
		||||
            data.toString(),
 | 
			
		||||
          );
 | 
			
		||||
          await fs.appendFile(absolutePath, data.toString());
 | 
			
		||||
        });
 | 
			
		||||
        cp.on('error', async (err) => {
 | 
			
		||||
          this.logger.error(
 | 
			
		||||
            '[panel][创建任务失败] 命令: %s, 错误信息: %j',
 | 
			
		||||
            command,
 | 
			
		||||
            err,
 | 
			
		||||
          );
 | 
			
		||||
          await fs.appendFile(absolutePath, JSON.stringify(err));
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        cp.on('exit', async (code) => {
 | 
			
		||||
          this.logger.info(
 | 
			
		||||
            '[panel][执行任务结束] 参数: %s, 退出码: %j',
 | 
			
		||||
            JSON.stringify(params),
 | 
			
		||||
            code,
 | 
			
		||||
          );
 | 
			
		||||
          await CrontabModel.update(
 | 
			
		||||
            { status: CrontabStatus.idle, pid: undefined },
 | 
			
		||||
            { where: { id } },
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -66,7 +66,7 @@ export default class ScheduleService {
 | 
			
		|||
    return taskLimit[this.taskLimitMap[runOrigin]](others, () => {
 | 
			
		||||
      return new Promise(async (resolve, reject) => {
 | 
			
		||||
        this.logger.info(
 | 
			
		||||
          `[panel][开始执行任务] 参数 ${JSON.stringify({
 | 
			
		||||
          `[panel][开始执行任务] 参数: ${JSON.stringify({
 | 
			
		||||
            ...others,
 | 
			
		||||
            command,
 | 
			
		||||
          })}`,
 | 
			
		||||
| 
						 | 
				
			
			@ -104,6 +104,14 @@ export default class ScheduleService {
 | 
			
		|||
          });
 | 
			
		||||
 | 
			
		||||
          cp.on('exit', async (code) => {
 | 
			
		||||
            this.logger.info(
 | 
			
		||||
              '[panel][执行任务结束] 参数: %s, 退出码: %j',
 | 
			
		||||
              JSON.stringify({
 | 
			
		||||
                ...others,
 | 
			
		||||
                command,
 | 
			
		||||
              }),
 | 
			
		||||
              code,
 | 
			
		||||
            );
 | 
			
		||||
            const endTime = dayjs();
 | 
			
		||||
            await callbacks.onEnd?.(
 | 
			
		||||
              cp,
 | 
			
		||||
| 
						 | 
				
			
			@ -196,7 +204,7 @@ export default class ScheduleService {
 | 
			
		|||
      },
 | 
			
		||||
      (err) => {
 | 
			
		||||
        this.logger.error(
 | 
			
		||||
          '[执行任务失败] 命令: %s, 错误信息: %j',
 | 
			
		||||
          '[panel][执行任务失败] 命令: %s, 错误信息: %j',
 | 
			
		||||
          command,
 | 
			
		||||
          err,
 | 
			
		||||
        );
 | 
			
		||||
| 
						 | 
				
			
			@ -223,7 +231,11 @@ export default class ScheduleService {
 | 
			
		|||
 | 
			
		||||
  async cancelIntervalTask({ id = 0, name }: ScheduleTaskType) {
 | 
			
		||||
    const _id = this.formatId(id);
 | 
			
		||||
    this.logger.info('[取消interval任务], 任务ID: %s, 任务名: %s', _id, name);
 | 
			
		||||
    this.logger.info(
 | 
			
		||||
      '[panel][取消interval任务], 任务ID: %s, 任务名: %s',
 | 
			
		||||
      _id,
 | 
			
		||||
      name,
 | 
			
		||||
    );
 | 
			
		||||
    this.intervalSchedule.removeById(_id);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -31,6 +31,14 @@ export function runCron(cmd: string, cron: ICron): Promise<number | void> {
 | 
			
		|||
 | 
			
		||||
      cp.on('exit', async (code) => {
 | 
			
		||||
        taskLimit.removeQueuedCron(cron.id);
 | 
			
		||||
        Logger.info(
 | 
			
		||||
          '[schedule][执行任务结束] 参数: %s, 退出码: %j',
 | 
			
		||||
          JSON.stringify({
 | 
			
		||||
            ...cron,
 | 
			
		||||
            command: cmd,
 | 
			
		||||
          }),
 | 
			
		||||
          code,
 | 
			
		||||
        );
 | 
			
		||||
        resolve({ ...cron, command: cmd, pid: cp.pid, code });
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user