Merge branch 'main' into fix--cancel-newest-try-advisory-lock

This commit is contained in:
Gabe Ruttner
2025-06-09 13:10:40 -07:00
committed by GitHub
2 changed files with 3 additions and 3 deletions

View File

@@ -2,7 +2,7 @@ import { Snippet } from '@/lib/generated/snips/types';
const snippet: Snippet = {
"language": "typescript ",
"content": "import sleep from '@hatchet-dev/typescript-sdk/util/sleep';\nimport axios from 'axios';\nimport { hatchet } from '../hatchet-client';\n\n// > Declaring a Task\nexport const cancellation = hatchet.task({\n name: 'cancellation',\n fn: async (_, { cancelled }) => {\n await sleep(10 * 1000);\n\n if (cancelled) {\n throw new Error('Task was cancelled');\n }\n\n return {\n Completed: true,\n };\n },\n});\n\n// > Abort Signal\nexport const abortSignal = hatchet.task({\n name: 'abort-signal',\n fn: async (_, { abortController }) => {\n try {\n const response = await axios.get('https://api.example.com/data', {\n signal: abortController.signal,\n });\n // Handle the response\n } catch (error) {\n if (axios.isCancel(error)) {\n // Request was canceled\n console.log('Request canceled');\n } else {\n // Handle other errors\n }\n }\n },\n});\n\n// see ./worker.ts and ./run.ts for how to run the workflow\n",
"content": "import sleep from '@hatchet-dev/typescript-sdk/util/sleep';\nimport axios from 'axios';\nimport { hatchet } from '../hatchet-client';\n\n// > Declaring a Task\nexport const cancellation = hatchet.task({\n name: 'cancellation',\n fn: async (_, ctx) => {\n await sleep(10 * 1000);\n\n if (ctx.cancelled) {\n throw new Error('Task was cancelled');\n }\n\n return {\n Completed: true,\n };\n },\n});\n\n// > Abort Signal\nexport const abortSignal = hatchet.task({\n name: 'abort-signal',\n fn: async (_, { abortController }) => {\n try {\n const response = await axios.get('https://api.example.com/data', {\n signal: abortController.signal,\n });\n // Handle the response\n } catch (error) {\n if (axios.isCancel(error)) {\n // Request was canceled\n console.log('Request canceled');\n } else {\n // Handle other errors\n }\n }\n },\n});\n\n// see ./worker.ts and ./run.ts for how to run the workflow\n",
"source": "out/typescript/cancellations/workflow.ts",
"blocks": {
"declaring_a_task": {

View File

@@ -5,10 +5,10 @@ import { hatchet } from '../hatchet-client';
// > Declaring a Task
export const cancellation = hatchet.task({
name: 'cancellation',
fn: async (_, { cancelled }) => {
fn: async (_, ctx) => {
await sleep(10 * 1000);
if (cancelled) {
if (ctx.cancelled) {
throw new Error('Task was cancelled');
}