mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 14:56:07 +08:00
增加任务运行数日志
This commit is contained in:
parent
ef4999be55
commit
e9416c23df
|
@ -33,7 +33,7 @@ const addCron = (
|
||||||
id,
|
id,
|
||||||
nodeSchedule.scheduleJob(id, schedule, async () => {
|
nodeSchedule.scheduleJob(id, schedule, async () => {
|
||||||
Logger.info(
|
Logger.info(
|
||||||
`[schedule] 时间: ${dayjs().format(
|
`[schedule][准备运行任务] 时间: ${dayjs().format(
|
||||||
'YYYY-MM-DD HH:mm:ss',
|
'YYYY-MM-DD HH:mm:ss',
|
||||||
)},运行命令: ${cmdStr}`,
|
)},运行命令: ${cmdStr}`,
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,12 +1,22 @@
|
||||||
import pLimit from 'p-limit';
|
import pLimit from 'p-limit';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
import { AuthDataType, AuthModel } from '../data/auth';
|
import { AuthDataType, AuthModel } from '../data/auth';
|
||||||
|
import Logger from '../loaders/logger';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
class TaskLimit {
|
class TaskLimit {
|
||||||
private oneLimit = pLimit(1);
|
private oneLimit = pLimit(1);
|
||||||
private updateLogLimit = pLimit(1);
|
private updateLogLimit = pLimit(1);
|
||||||
private cpuLimit = pLimit(Math.max(os.cpus().length, 4));
|
private cpuLimit = pLimit(Math.max(os.cpus().length, 4));
|
||||||
|
|
||||||
|
get cpuLimitActiveCount() {
|
||||||
|
return this.cpuLimit.activeCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
get cpuLimitPendingCount() {
|
||||||
|
return this.cpuLimit.pendingCount;
|
||||||
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.setCustomLimit();
|
this.setCustomLimit();
|
||||||
}
|
}
|
||||||
|
@ -26,6 +36,11 @@ class TaskLimit {
|
||||||
}
|
}
|
||||||
|
|
||||||
public runWithCpuLimit<T>(fn: () => Promise<T>): Promise<T> {
|
public runWithCpuLimit<T>(fn: () => Promise<T>): Promise<T> {
|
||||||
|
Logger.info(
|
||||||
|
`[schedule][任务加入队列] 时间: ${dayjs().format(
|
||||||
|
'YYYY-MM-DD HH:mm:ss',
|
||||||
|
)}, 运行中任务数: ${this.cpuLimitActiveCount}, 等待中任务数: ${this.cpuLimitPendingCount}`,
|
||||||
|
);
|
||||||
return this.cpuLimit(fn);
|
return this.cpuLimit(fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user