From e9416c23df28cb17cfc7b7042a40571067aa984e Mon Sep 17 00:00:00 2001 From: whyour Date: Fri, 25 Aug 2023 19:25:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BB=BB=E5=8A=A1=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E6=95=B0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/schedule/addCron.ts | 2 +- back/shared/pLimit.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/back/schedule/addCron.ts b/back/schedule/addCron.ts index 15f805ee..dada3e52 100644 --- a/back/schedule/addCron.ts +++ b/back/schedule/addCron.ts @@ -33,7 +33,7 @@ const addCron = ( id, nodeSchedule.scheduleJob(id, schedule, async () => { Logger.info( - `[schedule] 时间: ${dayjs().format( + `[schedule][准备运行任务] 时间: ${dayjs().format( 'YYYY-MM-DD HH:mm:ss', )},运行命令: ${cmdStr}`, ); diff --git a/back/shared/pLimit.ts b/back/shared/pLimit.ts index 822f3d91..db6df149 100644 --- a/back/shared/pLimit.ts +++ b/back/shared/pLimit.ts @@ -1,12 +1,22 @@ import pLimit from 'p-limit'; import os from 'os'; import { AuthDataType, AuthModel } from '../data/auth'; +import Logger from '../loaders/logger'; +import dayjs from 'dayjs'; class TaskLimit { private oneLimit = pLimit(1); private updateLogLimit = pLimit(1); private cpuLimit = pLimit(Math.max(os.cpus().length, 4)); + get cpuLimitActiveCount() { + return this.cpuLimit.activeCount; + } + + get cpuLimitPendingCount() { + return this.cpuLimit.pendingCount; + } + constructor() { this.setCustomLimit(); } @@ -26,6 +36,11 @@ class TaskLimit { } public runWithCpuLimit(fn: () => Promise): Promise { + Logger.info( + `[schedule][任务加入队列] 时间: ${dayjs().format( + 'YYYY-MM-DD HH:mm:ss', + )}, 运行中任务数: ${this.cpuLimitActiveCount}, 等待中任务数: ${this.cpuLimitPendingCount}`, + ); return this.cpuLimit(fn); }