From b8c14e64170e8b47b0a956147469239a1568164b Mon Sep 17 00:00:00 2001 From: Matt Aitken Date: Fri, 25 Apr 2025 18:19:10 +0100 Subject: [PATCH] Fix for completing batches (when there are idempotent runs) --- .../runEngine/services/batchTrigger.server.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/apps/webapp/app/runEngine/services/batchTrigger.server.ts b/apps/webapp/app/runEngine/services/batchTrigger.server.ts index 74ebf307f5..b2feca078f 100644 --- a/apps/webapp/app/runEngine/services/batchTrigger.server.ts +++ b/apps/webapp/app/runEngine/services/batchTrigger.server.ts @@ -564,20 +564,27 @@ export class RunEngineBatchTriggerService extends WithRunEngine { runIds: { push: runIds, }, + processingJobsCount: { + increment: runIds.length, + }, + }, + select: { + processingJobsCount: true, + runCount: true, }, }); - // if there are more items to process, requeue the batch - if (workingIndex < batch.runCount) { - return { status: "INCOMPLETE", workingIndex }; - } - //triggered all the runs - if (updatedBatch.runIds.length === updatedBatch.runCount) { + if (updatedBatch.processingJobsCount >= updatedBatch.runCount) { //if all the runs were idempotent, it's possible the batch is already completed await this._engine.tryCompleteBatch({ batchId: batch.id }); } + // if there are more items to process, requeue the batch + if (workingIndex < batch.runCount) { + return { status: "INCOMPLETE", workingIndex }; + } + return { status: "COMPLETE" }; }