Skip to content

Commit 7eda228

Browse files
authored
Prevent v2 batches from being resumed before all items have been created (#1614)
1 parent b3aa87e commit 7eda228

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

apps/webapp/app/v3/services/resumeBatchRun.server.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,25 @@ export class ResumeBatchRunService extends BaseService {
5151
return "ERROR";
5252
}
5353

54+
if (batchRun.batchVersion === "v2") {
55+
// Make sure batchRun.items.length is equal to or greater than batchRun.runCount
56+
if (batchRun.items.length < batchRun.runCount) {
57+
logger.debug("ResumeBatchRunService: All items aren't yet completed [v2]", {
58+
batchRunId: batchRun.id,
59+
batchRun: {
60+
id: batchRun.id,
61+
status: batchRun.status,
62+
itemsLength: batchRun.items.length,
63+
runCount: batchRun.runCount,
64+
},
65+
});
66+
67+
return "PENDING";
68+
}
69+
}
70+
5471
if (batchRun.items.some((item) => !finishedBatchRunStatuses.includes(item.status))) {
55-
logger.debug("ResumeBatchRunService: All items aren't yet completed", {
72+
logger.debug("ResumeBatchRunService: All items aren't yet completed [v1]", {
5673
batchRunId: batchRun.id,
5774
batchRun: {
5875
id: batchRun.id,

references/v3-catalog/src/trigger/batch.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,18 @@ export const batchV2TestTask = task({
376376

377377
for await (const liveRun0 of runs.subscribeToRun(response1.runs[0].id)) {
378378
logger.debug("subscribed to run0", { liveRun0 });
379+
380+
if (liveRun0.finishedAt) {
381+
break;
382+
}
379383
}
380384

381385
for await (const liveRun1 of runs.subscribeToRun(response1.runs[1].id)) {
382386
logger.debug("subscribed to run1", { liveRun1 });
387+
388+
if (liveRun1.finishedAt) {
389+
break;
390+
}
383391
}
384392
});
385393

0 commit comments

Comments
 (0)