Skip to content

Commit 13d378f

Browse files
authored
v4: batches can only complete when all their runs have been created (#2101)
* v4: batches can only complete when all their runs have been created * Fix flaky runs replication test
1 parent 1a6a9ca commit 13d378f

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

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
}

apps/webapp/test/runsReplicationService.part1.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ describe("RunsReplicationService (part 1/2)", () => {
128128

129129
expect(transactionSpan).not.toBeNull();
130130
expect(transactionSpan?.attributes["transaction.parse_duration_ms"]).toBeGreaterThan(0);
131-
expect(transactionSpan?.attributes["transaction.parse_duration_ms"]).toBeLessThan(1);
131+
expect(transactionSpan?.attributes["transaction.parse_duration_ms"]).toBeLessThan(5);
132132

133133
await runsReplicationService.stop();
134134
}

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)