feat!: namespace-owned configuration and lifecycle - #5
Merged
Conversation
The global `Settings` object is gone. `logger` is now a `WorkflowNamespace` option inherited by every workflow, queue, worker and step; the default redis connection is the namespace's `redis` option; metrics stay reachable through the already-inherited `workerOptions.metrics`. Shutdown moves to the namespace too: one exit hook drains every worker and disconnects redis on a process signal, replacing the per-worker hook in `work()`. Opt out with `autoClose: false`; an explicit `close()` unregisters the hook so a later signal can't close twice. Adds `NonRecoverableError`, which dead-letters a job at once instead of burning the remaining `maxAttempts` — a retry that cannot possibly succeed is wasted work. The worker throws it when a job's stored payload no longer validates against the workflow `schema` (a job enqueued before a schema change), and logs a warning naming the mismatch, since a retry would only re-read the same payload. Also exposes `workflow.getMetrics()`. BREAKING CHANGE: `Settings` is no longer exported. Pass `logger` and `redis` to `WorkflowNamespace` instead of `Settings.logger` / `Settings.defaultConnection`, and namespace-level metrics via `workerOptions.metrics`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Removes the global
Settingsobject; aWorkflowNamespacenow owns configuration, shutdown, and the schema-mismatch failure path.Changes
loggeris a namespace option inherited by every workflow, queue, worker and step (via aQueue.loggeraccessor mirroringget prefix()). The default redis connection is the existingredisoption; namespace-level metrics go through the already-inheritedworkerOptions.metrics.asyncExitHookin.work()is gone. One namespace hook drains every worker and disconnects redis onSIGINT/SIGTERM/exit. Enabled by default; opt out withautoClose: false. An explicitclose()unregisters the hook so a later signal can't close twice.NonRecoverableError. Dead-letters a job immediately instead of burning the remainingmaxAttempts. ThefailLua script takes a newnoRetryarg.NonRecoverableErrorwhen a job's stored payload no longer validates against the workflowschema(a job enqueued before a schema change) — a retry would only re-read the same payload.workflow.getMetrics()exposes the queue's{ active, waiting, delayed }depths.Breaking
Settingsis no longer exported. PassloggerandredistoWorkflowNamespaceinstead ofSettings.logger/Settings.defaultConnection, and namespace-level metrics viaworkerOptions.metrics.Tests
66 pass, including two new ones:
NonRecoverableErrorskipping a 5-attempt budget (verified red before the Lua change), and a stale-schema payload warning + failing without retry. Typecheck, lint and build clean.