Skip to content

Commit 8b33031

Browse files
committed
Fix for batch waits not working
1 parent 98fad73 commit 8b33031

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,15 @@ export class BatchTriggerV3Service extends WithRunEngine {
204204

205205
//block the parent with any existing children
206206
if (body.resumeParentOnCompletion && body.parentRunId) {
207-
await this.#blockParentRun({
208-
parentRunId: body.parentRunId,
209-
childFriendlyIds: runs.flatMap((r) => (r.isCached ? [r.id] : [])),
210-
environment,
211-
});
207+
const existingChildFriendlyIds = runs.flatMap((r) => (r.isCached ? [r.id] : []));
208+
209+
if (existingChildFriendlyIds.length > 0) {
210+
await this.#blockParentRun({
211+
parentRunId: body.parentRunId,
212+
childFriendlyIds: existingChildFriendlyIds,
213+
environment,
214+
});
215+
}
212216
}
213217

214218
// Calculate how many new runs we need to create
@@ -885,8 +889,8 @@ export class BatchTriggerV3Service extends WithRunEngine {
885889
}) {
886890
const runsWithAssociatedWaitpoints = await this._prisma.taskRun.findMany({
887891
where: {
888-
friendlyId: {
889-
in: childFriendlyIds,
892+
id: {
893+
in: childFriendlyIds.map((r) => RunId.fromFriendlyId(r)),
890894
},
891895
},
892896
select: {
@@ -899,7 +903,7 @@ export class BatchTriggerV3Service extends WithRunEngine {
899903
});
900904

901905
await this._engine.blockRunWithWaitpoint({
902-
runId: parentRunId,
906+
runId: RunId.fromFriendlyId(parentRunId),
903907
waitpointId: runsWithAssociatedWaitpoints.flatMap((r) =>
904908
r.associatedWaitpoint ? [r.associatedWaitpoint.id] : []
905909
),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export class TriggerTaskServiceV2 extends WithRunEngine {
163163
//todo we will pass in the `parentRun` and `resumeParentOnCompletion`
164164
const parentRun = body.options?.parentRunId
165165
? await this._prisma.taskRun.findFirst({
166-
where: { friendlyId: body.options.parentRunId },
166+
where: { id: RunId.fromFriendlyId(body.options.parentRunId) },
167167
})
168168
: undefined;
169169

@@ -298,7 +298,7 @@ export class TriggerTaskServiceV2 extends WithRunEngine {
298298
tags,
299299
oneTimeUseToken: options.oneTimeUseToken,
300300
parentTaskRunId: parentRun?.id,
301-
rootTaskRunId: parentRun?.rootTaskRunId ?? undefined,
301+
rootTaskRunId: parentRun?.rootTaskRunId ?? parentRun?.id,
302302
batchId: body.options?.parentBatch ?? undefined,
303303
resumeParentOnCompletion: body.options?.resumeParentOnCompletion,
304304
depth,

packages/trigger-sdk/src/v3/shared.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,8 @@ export async function batchTriggerByIdAndWait<TTask extends AnyTask>(
791791
})
792792
),
793793
dependentAttempt: ctx.attempt.id,
794+
parentRunId: ctx.run.id,
795+
resumeParentOnCompletion: true,
794796
},
795797
{
796798
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
@@ -1127,6 +1129,8 @@ export async function batchTriggerAndWaitTasks<TTasks extends readonly AnyTask[]
11271129
})
11281130
),
11291131
dependentAttempt: ctx.attempt.id,
1132+
parentRunId: ctx.run.id,
1133+
resumeParentOnCompletion: true,
11301134
},
11311135
{
11321136
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
@@ -1234,6 +1238,8 @@ async function batchTrigger_internal<TRunTypes extends AnyRunTypes>(
12341238
): Promise<BatchRunHandleFromTypes<TRunTypes>> {
12351239
const apiClient = apiClientManager.clientOrThrow();
12361240

1241+
const ctx = taskContext.ctx;
1242+
12371243
const response = await apiClient.batchTriggerV2(
12381244
{
12391245
items: await Promise.all(
@@ -1259,6 +1265,7 @@ async function batchTrigger_internal<TRunTypes extends AnyRunTypes>(
12591265
parentAttempt: taskContext.ctx?.attempt.id,
12601266
metadata: item.options?.metadata,
12611267
maxDuration: item.options?.maxDuration,
1268+
parentRunId: ctx?.run.id,
12621269
},
12631270
};
12641271
})
@@ -1430,13 +1437,13 @@ async function batchTriggerAndWait_internal<TIdentifier extends string, TPayload
14301437
maxAttempts: item.options?.maxAttempts,
14311438
metadata: item.options?.metadata,
14321439
maxDuration: item.options?.maxDuration,
1433-
resumeParentOnCompletion: true,
1434-
parentRunId: ctx.run.id,
14351440
},
14361441
};
14371442
})
14381443
),
14391444
dependentAttempt: ctx.attempt.id,
1445+
resumeParentOnCompletion: true,
1446+
parentRunId: ctx.run.id,
14401447
},
14411448
{
14421449
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,

0 commit comments

Comments
 (0)