Skip to content

Commit d3b095b

Browse files
committed
Durations waits use the API to create/block with a waitpoint, not the runtime
1 parent 8aa47a9 commit d3b095b

File tree

20 files changed

+337
-457
lines changed

20 files changed

+337
-457
lines changed

apps/webapp/app/routes/api.v1.dev.runs.$runFriendlyId.snapshots.$snapshotFriendlyId.wait.duration.ts

Lines changed: 0 additions & 63 deletions
This file was deleted.

apps/webapp/app/routes/api.v1.worker-actions.runs.$runFriendlyId.snapshots.$snapshotFriendlyId.wait.duration.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { json, TypedResponse } from "@remix-run/server-runtime";
2+
import { WaitForDurationRequestBody, WaitForDurationResponseBody } from "@trigger.dev/core/v3";
3+
import { RunId } from "@trigger.dev/core/v3/apps";
4+
5+
import { z } from "zod";
6+
import { prisma } from "~/db.server";
7+
import { logger } from "~/services/logger.server";
8+
import { createActionApiRoute } from "~/services/routeBuilders/apiBuilder.server";
9+
import { resolveIdempotencyKeyTTL } from "~/utils/idempotencyKeys.server";
10+
import { engine } from "~/v3/runEngine.server";
11+
12+
const { action } = createActionApiRoute(
13+
{
14+
body: WaitForDurationRequestBody,
15+
params: z.object({
16+
runFriendlyId: z.string(),
17+
}),
18+
method: "POST",
19+
},
20+
async ({ authentication, body, params }): Promise<TypedResponse<WaitForDurationResponseBody>> => {
21+
const { runFriendlyId } = params;
22+
const runId = RunId.toId(runFriendlyId);
23+
24+
try {
25+
const run = await prisma.taskRun.findFirst({
26+
where: {
27+
id: runId,
28+
runtimeEnvironmentId: authentication.environment.id,
29+
},
30+
});
31+
32+
if (!run) {
33+
throw new Response("You don't have permissions for this run", { status: 401 });
34+
}
35+
36+
const idempotencyKeyExpiresAt = body.idempotencyKeyTTL
37+
? resolveIdempotencyKeyTTL(body.idempotencyKeyTTL)
38+
: undefined;
39+
40+
const { waitpoint } = await engine.createDateTimeWaitpoint({
41+
projectId: authentication.environment.project.id,
42+
environmentId: authentication.environment.id,
43+
completedAfter: body.date,
44+
idempotencyKey: body.idempotencyKey,
45+
idempotencyKeyExpiresAt: idempotencyKeyExpiresAt,
46+
});
47+
48+
const waitResult = await engine.blockRunWithWaitpoint({
49+
runId: run.id,
50+
waitpoints: waitpoint.id,
51+
environmentId: authentication.environment.id,
52+
projectId: authentication.environment.project.id,
53+
organizationId: authentication.environment.organization.id,
54+
releaseConcurrency: {
55+
releaseQueue: true,
56+
},
57+
});
58+
59+
return json({
60+
waitUntil: body.date,
61+
waitpoint: {
62+
id: waitpoint.friendlyId,
63+
},
64+
});
65+
} catch (error) {
66+
logger.error("Failed to wait for duration dev", {
67+
environmentId: authentication.environment.id,
68+
error,
69+
});
70+
throw error;
71+
}
72+
}
73+
);
74+
75+
export { action };

apps/webapp/app/routes/api.v1.runs.$runFriendlyId.waitpoints.tokens.$waitpointFriendlyId.wait.ts renamed to apps/webapp/app/routes/engine.v1.runs.$runFriendlyId.waitpoints.tokens.$waitpointFriendlyId.wait.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const { action } = createActionApiRoute(
5252
waitpoints: [waitpointId],
5353
environmentId: authentication.environment.id,
5454
projectId: authentication.environment.project.id,
55+
organizationId: authentication.environment.organization.id,
5556
failAfter: timeout,
5657
});
5758

apps/webapp/app/v3/services/worker/workerGroupTokenService.server.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -718,24 +718,6 @@ export class AuthenticatedWorkerInstance extends WithRunEngine {
718718
});
719719
}
720720

721-
async waitForDuration({
722-
runFriendlyId,
723-
snapshotFriendlyId,
724-
date,
725-
}: {
726-
runFriendlyId: string;
727-
snapshotFriendlyId: string;
728-
date: Date;
729-
}): Promise<WaitForDurationResult> {
730-
return await this._engine.waitForDuration({
731-
runId: fromFriendlyId(runFriendlyId),
732-
snapshotId: fromFriendlyId(snapshotFriendlyId),
733-
date,
734-
workerId: this.workerInstanceId,
735-
runnerId: this.runnerId,
736-
});
737-
}
738-
739721
async getLatestSnapshot({ runFriendlyId }: { runFriendlyId: string }) {
740722
return await this._engine.getRunExecutionData({
741723
runId: fromFriendlyId(runFriendlyId),

0 commit comments

Comments
 (0)