Skip to content

Commit

Permalink
Fix an issue where runs were stuck executing when a child task failed…
Browse files Browse the repository at this point in the history
… and the parent task retried
  • Loading branch information
ericallam committed Jan 17, 2024
1 parent 831860e commit 6c4047c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/weak-badgers-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@trigger.dev/sdk": patch
---

Fix an issue where runs were stuck executing when a child task failed and the parent task retried
2 changes: 2 additions & 0 deletions packages/trigger-sdk/src/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,8 @@ export class IO {
await this._apiClient.failTask(this._id, task.id, {
error: error.cause.output as any,
});

throw error;
}

const parsedError = ErrorWithStackSchema.safeParse(error);
Expand Down
50 changes: 49 additions & 1 deletion references/job-catalog/src/background-fetch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createExpressServer } from "@trigger.dev/express";
import { TriggerClient, eventTrigger } from "@trigger.dev/sdk";
import { TriggerClient, eventTrigger, invokeTrigger } from "@trigger.dev/sdk";
import { z } from "zod";

export const client = new TriggerClient({
Expand Down Expand Up @@ -53,4 +53,52 @@ client.defineJob({
},
});

client.defineJob({
id: "test-background-fetch-rety-stuck-error",
name: "Reproduce stuck error",
version: "0.0.1",
trigger: invokeTrigger({
schema: z.object({
url: z.string(),
}),
}),
run: async (payload, io, ctx) => {
await io.runTask(
"test-background-fetch-retry",
async (task) => {
const response = await io.backgroundFetchResponse<any>(
payload.url,
payload.url,
{ method: "GET" },
{
timeout: {
durationInMs: 1000,
retry: {
limit: 2,
factor: 2,
minTimeoutInMs: 3000, // 3 secs
maxTimeoutInMs: 10000, // 10 secs
randomize: true,
},
},
}
);

console.log(`Got response`, response);
},
{
retry: {
limit: 4,
factor: 1.8,
minTimeoutInMs: 1500,
maxTimeoutInMs: 30000,
randomize: true,
},
}
);

await io.logger.info("Got here");
},
});

createExpressServer(client);

0 comments on commit 6c4047c

Please sign in to comment.