Skip to content

Commit 107f4dc

Browse files
authored
fix(deployments): retry transient depot build init failures (#2586)
The Depot build init with `depot.build.v1.BuildService.createBuild` fails surprisingly often due to transient errors, causing the whole deployment to fail. This PR adds a simple retry mechanism with backoff using p-retry. This should improve the failure rate.
1 parent b90f3e2 commit 107f4dc

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

apps/webapp/app/routes/api.v1.deployments.$deploymentId.progress.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,21 @@ export async function action({ request, params }: ActionFunctionArgs) {
5555
},
5656
(error) => {
5757
switch (error.type) {
58-
case "failed_to_extend_deployment_timeout":
58+
case "failed_to_extend_deployment_timeout": {
59+
logger.warn("Failed to extend deployment timeout", { error: error.cause });
5960
return new Response(null, { status: 204 }); // ignore these errors for now
61+
}
6062
case "deployment_not_found":
6163
return json({ error: "Deployment not found" }, { status: 404 });
6264
case "deployment_cannot_be_progressed":
6365
return json(
6466
{ error: "Deployment is not in a progressable state (PENDING or INSTALLING)" },
6567
{ status: 409 }
6668
);
67-
case "failed_to_create_remote_build":
69+
case "failed_to_create_remote_build": {
70+
logger.error("Failed to create remote Depot build", { error: error.cause });
6871
return json({ error: "Failed to create remote build" }, { status: 500 });
72+
}
6973
case "other":
7074
default:
7175
error.type satisfies "other";

apps/webapp/app/v3/remoteImageBuilder.server.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { type ExternalBuildData } from "@trigger.dev/core/v3";
33
import { type Project } from "@trigger.dev/database";
44
import { prisma } from "~/db.server";
55
import { env } from "~/env.server";
6+
import pRetry from "p-retry";
7+
import { logger } from "~/services/logger.server";
68

79
export async function createRemoteImageBuild(
810
project: Project
@@ -13,11 +15,22 @@ export async function createRemoteImageBuild(
1315

1416
const builderProjectId = await createBuilderProjectIfNotExists(project);
1517

16-
const result = await depot.build.v1.BuildService.createBuild(
17-
{ projectId: builderProjectId },
18+
const result = await pRetry(
19+
() =>
20+
depot.build.v1.BuildService.createBuild(
21+
{ projectId: builderProjectId },
22+
{
23+
headers: {
24+
Authorization: `Bearer ${env.DEPOT_TOKEN}`,
25+
},
26+
}
27+
),
1828
{
19-
headers: {
20-
Authorization: `Bearer ${env.DEPOT_TOKEN}`,
29+
retries: 3,
30+
minTimeout: 200,
31+
maxTimeout: 2000,
32+
onFailedAttempt: (error) => {
33+
logger.error("Failed attempt to create remote Depot build", { error });
2134
},
2235
}
2336
);

apps/webapp/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
"openai": "^4.33.1",
167167
"p-limit": "^6.2.0",
168168
"p-map": "^6.0.0",
169+
"p-retry": "^4.6.1",
169170
"parse-duration": "^2.1.0",
170171
"posthog-js": "^1.93.3",
171172
"posthog-node": "4.17.1",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)