Skip to content

Commit

Permalink
Merge pull request #177 from upstash/hotifx-add-call-fail-warning
Browse files Browse the repository at this point in the history
Hotifx add call fail warning
  • Loading branch information
CahidArda authored Sep 6, 2024
2 parents b8955fe + 9d22fef commit 2381dc6
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion examples/workflow/cloudflare-workers-hono/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "cloudflare-workers",
"version": "0.0.0",
"dependencies": {
"@upstash/qstash": "^2.7.0-workflow-alpha.4",
"@upstash/qstash": "^2.7.4",
"hono": "^4.5.8"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/workflow/cloudflare-workers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"wrangler": "^3.60.3"
},
"dependencies": {
"@upstash/qstash": "^2.7.0-workflow-alpha.4"
"@upstash/qstash": "^2.7.4"
}
}
2 changes: 1 addition & 1 deletion examples/workflow/hono/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"dev": "bun run --hot -p 3001 src/index.ts"
},
"dependencies": {
"@upstash/qstash": "^2.7.0-workflow-alpha.4",
"@upstash/qstash": "^2.7.4",
"hono": "^4.5.8"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/workflow/nextjs-pages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"@upstash/qstash": "file:../../../dist",
"@upstash/qstash": "^2.7.4",
"next": "14.2.8",
"react": "^18",
"react-dom": "^18"
Expand Down
2 changes: 1 addition & 1 deletion examples/workflow/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"@upstash/qstash": "^2.7.0-workflow-alpha.4",
"@upstash/qstash": "^2.7.4",
"next": "14.2.4",
"react": "^18",
"react-dom": "^18"
Expand Down
2 changes: 1 addition & 1 deletion examples/workflow/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"postinstall": "nuxt prepare"
},
"dependencies": {
"@upstash/qstash": "^2.7.0-workflow-alpha.4",
"@upstash/qstash": "^2.7.4",
"nuxt": "^3.12.4",
"vue": "latest"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/workflow/solidjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@solidjs/meta": "0.29.4",
"@solidjs/router": "^0.13.6",
"@solidjs/start": "^1.0.2",
"@upstash/qstash": "^2.7.0-workflow-alpha.4",
"@upstash/qstash": "^2.7.4",
"solid-js": "^1.8.17"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion examples/workflow/sveltekit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
},
"type": "module",
"dependencies": {
"@upstash/qstash": "^2.7.0-workflow-alpha.4"
"@upstash/qstash": "^2.7.4"
}
}
16 changes: 13 additions & 3 deletions src/client/workflow/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,16 @@ export class WorkflowContext<TInitialPayload = unknown> {
* );
* ```
*
* tries to parse the result of the request as JSON. If it's
* not a JSON which can be parsed, simply returns the response
* body as it is.
*
* @param stepName
* @param url url to call
* @param method call method
* @param body call body
* @param headers call headers
* @returns call result
* @returns call result (parsed as JSON if possible)
*/
public async call<TResult = unknown, TBody = unknown>(
stepName: string,
Expand All @@ -269,9 +273,15 @@ export class WorkflowContext<TInitialPayload = unknown> {
body?: TBody,
headers?: Record<string, string>
) {
return await this.addStep(
new LazyCallStep<TResult>(stepName, url, method, body, headers ?? {})
const result = await this.addStep(
new LazyCallStep<string>(stepName, url, method, body, headers ?? {})
);

try {
return JSON.parse(result) as TResult;
} catch {
return result as TResult;
}
}

/**
Expand Down
10 changes: 9 additions & 1 deletion src/client/workflow/workflow-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,16 @@ export const handleThirdPartyCallResult = async (

// eslint-disable-next-line @typescript-eslint/no-magic-numbers
if (!(callbackMessage.status >= 200 && callbackMessage.status < 300)) {
await debug?.log("WARN", "SUBMIT_THIRD_PARTY_RESULT", callbackMessage);
await debug?.log("WARN", "SUBMIT_THIRD_PARTY_RESULT", {
status: callbackMessage.status,
body: atob(callbackMessage.body),
});
// this callback will be retried by the QStash, we just ignore it
console.warn(
`Workflow Warning: "context.call" failed with status ${callbackMessage.status}` +
` and will retry (if there are retries remaining).` +
` Error Message:\n${atob(callbackMessage.body)}`
);
return ok("call-will-retry");
}

Expand Down

0 comments on commit 2381dc6

Please sign in to comment.