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" }; }