修复有可能手动运行任务无日志

This commit is contained in:
whyour
2024-05-25 00:28:55 +08:00
parent 8dd379b6b9
commit b309ac7613
7 changed files with 30 additions and 17 deletions
+12
View File
@@ -15,6 +15,9 @@ class TaskLimit {
private cronLimit = new PQueue({
concurrency: Math.max(os.cpus().length, 4),
});
private manualCronoLimit = new PQueue({
concurrency: Math.max(os.cpus().length, 4),
});
get cronLimitActiveCount() {
return this.cronLimit.pending;
@@ -71,6 +74,7 @@ class TaskLimit {
public async setCustomLimit(limit?: number) {
if (limit) {
this.cronLimit.concurrency = limit;
this.manualCronoLimit.concurrency = limit;
return;
}
await SystemModel.sync();
@@ -79,6 +83,7 @@ class TaskLimit {
});
if (doc?.info?.cronConcurrency) {
this.cronLimit.concurrency = doc.info.cronConcurrency;
this.manualCronoLimit.concurrency = doc.info.cronConcurrency;
}
}
@@ -89,6 +94,13 @@ class TaskLimit {
return this.cronLimit.add(fn, options);
}
public async manualRunWithCronLimit<T>(
fn: () => Promise<T>,
options?: Partial<QueueAddOptions>,
): Promise<T | void> {
return this.manualCronoLimit.add(fn, options);
}
public runDependeny<T>(
dependency: Dependence,
fn: IDependencyFn<T>,