diff --git a/pkgs/website/src/assets/cover-images/pgflow-0-6-1-worker-config-in-handler-context.png b/pkgs/website/src/assets/cover-images/pgflow-0-6-1-worker-config-in-handler-context.png new file mode 100644 index 000000000..5d62149f4 Binary files /dev/null and b/pkgs/website/src/assets/cover-images/pgflow-0-6-1-worker-config-in-handler-context.png differ diff --git a/pkgs/website/src/content/docs/concepts/context.mdx b/pkgs/website/src/content/docs/concepts/context.mdx index deeeac665..2bb96a792 100644 --- a/pkgs/website/src/content/docs/concepts/context.mdx +++ b/pkgs/website/src/content/docs/concepts/context.mdx @@ -217,34 +217,19 @@ interface ResolvedFlowWorkerConfig { The most common use case is detecting when a message is on its final retry attempt: ```typescript "ctx.workerConfig" "ctx.rawMessage" ".read_ct" ".retry.limit" -// Queue handler - detect final retry attempt -async function processOrder(input, ctx) { - const isLastRetry = ctx.rawMessage.read_ct >= ctx.workerConfig.retry.limit; +async function sendEmail(input, ctx) { + const isLastAttempt = ctx.rawMessage.read_ct >= ctx.workerConfig.retry.limit; - if (isLastRetry) { - // Send alert or fallback action before final failure - await sendFailureAlert(input.orderId, ctx.workerConfig.queueName); + if (isLastAttempt) { + // Use fallback email service on final attempt + return await sendWithFallbackProvider(input.to, input.subject, input.body); } - return processOrderLogic(input); + // Use primary email service for regular attempts + return await sendWithPrimaryProvider(input.to, input.subject, input.body); } ``` -```typescript "ctx.workerConfig" ".visibilityTimeout" -// Flow handler - access worker configuration -.step({ slug: 'api_call' }, async (input, ctx) => { - // Use worker's visibility timeout to set safe API timeout - const safeTimeout = (ctx.workerConfig.visibilityTimeout - 2) * 1000; // 2s buffer - - console.log(`Using ${safeTimeout}ms timeout based on worker visibility timeout`); - - const response = await fetch(input.url, { - signal: AbortSignal.timeout(safeTimeout) - }); - - return await response.json(); -}) -``` -Your pgflow installation is now updated with the latest features, bug fixes, and database schema improvements! \ No newline at end of file +Your pgflow installation is now updated with the latest features, bug fixes, and database schema improvements! diff --git a/pkgs/website/src/content/docs/news/pgflow-0-6-1-worker-config-in-handler-context.mdx b/pkgs/website/src/content/docs/news/pgflow-0-6-1-worker-config-in-handler-context.mdx new file mode 100644 index 000000000..2957fe591 --- /dev/null +++ b/pkgs/website/src/content/docs/news/pgflow-0-6-1-worker-config-in-handler-context.mdx @@ -0,0 +1,50 @@ +--- +draft: false +title: 'pgflow 0.6.1: Worker Configuration in Handler Context' +description: 'Handlers can now access worker configuration through context.workerConfig for intelligent decision-making based on retry limits, concurrency settings, and other worker parameters.' +date: 2025-09-05 +authors: + - jumski +tags: + - release + - edge-worker + - context + - configuration +featured: true +cover: + alt: 'pgflow 0.6.1 worker config in handler context cover image' + image: '../../../assets/cover-images/pgflow-0-6-1-worker-config-in-handler-context.png' +--- + +import { Aside } from "@astrojs/starlight/components"; + +pgflow 0.6.1 adds `workerConfig` to the handler execution context, enabling intelligent decision-making based on worker configuration. + +## Worker Configuration in Context + +Handlers now have access to the complete worker configuration through `context.workerConfig` ([#200](https://github.com/pgflow-dev/pgflow/issues/200)). This enables smarter handlers that can adapt their behavior based on retry limits, concurrency settings, timeouts, and other worker parameters. + +```typescript +async function sendEmail(input, context) { + const isLastAttempt = context.rawMessage.read_ct >= context.workerConfig.retry.limit; + + if (isLastAttempt) { + // Use fallback email service on final attempt + return await sendWithFallbackProvider(input.to, input.subject, input.body); + } + + // Use primary email service for regular attempts + return await sendWithPrimaryProvider(input.to, input.subject, input.body); +} +``` + +See the [context documentation](/concepts/context/#workerconfig) for complete details on available configuration properties and additional examples. + + +## Bug Fix + +This release also fixes retry strategy validation to only enforce the 50-limit cap for exponential retry strategy, allowing higher limits for fixed strategy when needed ([#199](https://github.com/pgflow-dev/pgflow/issues/199)). + +## Updating to 0.6.1 + +Follow our [update guide](/getting-started/update-pgflow/) for step-by-step upgrade instructions. \ No newline at end of file