Skip to content

Commit

Permalink
fix: pass all params to context in failureFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
CahidArda committed Dec 23, 2024
1 parent c61794b commit 5addd9f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/serve/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ export const serveBase = <
qstashClient,
initialPayloadParser,
routeFunction,
failureFunction
failureFunction,
env,
retries,
debug
);
if (failureCheck.isErr()) {
// unexpected error during handleFailure
Expand Down
32 changes: 26 additions & 6 deletions src/workflow-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,16 @@ describe("Workflow Parser", () => {
};

// no failureFunction
const result1 = await handleFailure(request, "", client, initialPayloadParser, routeFunction);
const result1 = await handleFailure(
request,
"",
client,
initialPayloadParser,
routeFunction,
undefined,
{},
3
);
expect(result1.isOk()).toBeTrue();
expect(result1.isOk() && result1.value === "not-failure-callback").toBeTrue();

Expand All @@ -764,7 +773,9 @@ describe("Workflow Parser", () => {
client,
initialPayloadParser,
routeFunction,
failureFunction
failureFunction,
{},
0
);
expect(result2.isOk()).toBeTrue();
expect(result2.isOk() && result2.value === "not-failure-callback").toBeTrue();
Expand All @@ -789,7 +800,10 @@ describe("Workflow Parser", () => {
"",
client,
initialPayloadParser,
routeFunction
routeFunction,
undefined,
{},
0
);
expect(result.isErr()).toBeTrue();
expect(result.isErr() && result.error.name).toBe(WorkflowError.name);
Expand Down Expand Up @@ -817,7 +831,9 @@ describe("Workflow Parser", () => {
client,
initialPayloadParser,
routeFunction,
failureFunction
failureFunction,
{},
3
);
expect(result.isErr()).toBeTrue();
expect(result.isErr() && result.error.message).toBe("my-error");
Expand Down Expand Up @@ -847,7 +863,9 @@ describe("Workflow Parser", () => {
client,
initialPayloadParser,
routeFunction,
failureFunction
failureFunction,
{},
0
);
expect(result.isOk()).toBeTrue();
expect(result.isOk() && result.value).toBe("is-failure-callback");
Expand All @@ -867,7 +885,9 @@ describe("Workflow Parser", () => {
client,
initialPayloadParser,
routeFunctionWithoutSteps,
failureFunction
failureFunction,
{},
3
);

expect(result.isErr());
Expand Down
6 changes: 5 additions & 1 deletion src/workflow-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,9 @@ export const handleFailure = async <TInitialPayload>(
WorkflowServeOptions<Response, TInitialPayload>
>["initialPayloadParser"],
routeFunction: RouteFunction<TInitialPayload>,
failureFunction?: WorkflowServeOptions<Response, TInitialPayload>["failureFunction"],
failureFunction: WorkflowServeOptions<Response, TInitialPayload>["failureFunction"],
env: WorkflowServeOptions["env"],
retries: WorkflowServeOptions["retries"],
debug?: WorkflowLogger
): Promise<Ok<"is-failure-callback" | "not-failure-callback", never> | Err<never, Error>> => {
if (request.headers.get(WORKFLOW_FAILURE_HEADER) !== "true") {
Expand Down Expand Up @@ -350,6 +352,8 @@ export const handleFailure = async <TInitialPayload>(
url: url,
failureUrl: url,
debug,
env,
retries,
});

// attempt running routeFunction until the first step
Expand Down

0 comments on commit 5addd9f

Please sign in to comment.