Skip to content

Commit 0605a5a

Browse files
committed
v4: batches can only complete when all their runs have been created
1 parent 7c791dd commit 0605a5a

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

apps/webapp/app/runEngine/services/batchTrigger.server.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,13 @@ export class RunEngineBatchTriggerService extends WithRunEngine {
576576

577577
//triggered all the runs
578578
if (updatedBatch.processingJobsCount >= updatedBatch.runCount) {
579+
logger.debug("[RunEngineBatchTrigger][processBatchTaskRun] All runs created", {
580+
batchId: batch.friendlyId,
581+
processingJobsCount: updatedBatch.processingJobsCount,
582+
runCount: updatedBatch.runCount,
583+
workingIndex,
584+
});
585+
579586
//if all the runs were idempotent, it's possible the batch is already completed
580587
await this._engine.tryCompleteBatch({ batchId: batch.id });
581588
}

internal-packages/run-engine/src/engine/systems/batchSystem.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export class BatchSystem {
4242
select: {
4343
status: true,
4444
runtimeEnvironmentId: true,
45+
processingJobsCount: true,
46+
runCount: true,
4547
},
4648
where: {
4749
id: batchId,
@@ -58,6 +60,15 @@ export class BatchSystem {
5860
return;
5961
}
6062

63+
if (batch.processingJobsCount < batch.runCount) {
64+
this.$.logger.debug("#tryCompleteBatch: Not all runs are created yet", {
65+
batchId,
66+
processingJobsCount: batch.processingJobsCount,
67+
runCount: batch.runCount,
68+
});
69+
return;
70+
}
71+
6172
const runs = await this.$.prisma.taskRun.findMany({
6273
select: {
6374
id: true,

0 commit comments

Comments
 (0)