perf: 批量运行优化,支持普通运行和强制重新运行

This commit is contained in:
xiaojunnuo
2025-12-29 15:31:33 +08:00
parent 07f0aa45ef
commit 039c62b09b
7 changed files with 106 additions and 29 deletions
@@ -898,7 +898,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
}
}
async batchRerun(ids: number[], userId: any) {
async batchRerun(ids: number[], userId: any, force: boolean) {
if (!isPlus()) {
throw new NeedVIPException("此功能需要升级专业版");
}
@@ -919,18 +919,20 @@ export class PipelineService extends BaseService<PipelineEntity> {
ids = list.map(item => item.id);
//异步执行
this.startBatchRerun(ids);
this.startBatchRerun(userId,ids, force);
}
async startBatchRerun(ids: number[]) {
//20条一批
const batchSize = 20;
for (let i = 0; i < ids.length; i += batchSize) {
const batchIds = ids.slice(i, i + batchSize);
const batchPromises = batchIds.map(async (id) => {
await this.run(id, null, "ALL");
startBatchRerun(userId:number, ids: number[], force: boolean) {
for (const id of ids) {
executorQueue.addTask(userId,{
task: async () => {
if (force) {
await this.run(id, null, "ALL");
} else {
await this.run(id, null);
}
}
});
await Promise.all(batchPromises);
}
}