Skip to content

feat!: namespace-owned configuration and lifecycle - #5

Merged
LouisHaftmann merged 3 commits into
mainfrom
feat/namespace-owned-configuration
Jul 30, 2026
Merged

feat!: namespace-owned configuration and lifecycle#5
LouisHaftmann merged 3 commits into
mainfrom
feat/namespace-owned-configuration

Conversation

@LouisHaftmann

Copy link
Copy Markdown
Contributor

Removes the global Settings object; a WorkflowNamespace now owns configuration, shutdown, and the schema-mismatch failure path.

Changes

  • Namespace-owned settings. logger is a namespace option inherited by every workflow, queue, worker and step (via a Queue.logger accessor mirroring get prefix()). The default redis connection is the existing redis option; namespace-level metrics go through the already-inherited workerOptions.metrics.
  • Namespace-level auto-close. The per-worker asyncExitHook in .work() is gone. One namespace hook drains every worker and disconnects redis on SIGINT/SIGTERM/exit. Enabled by default; opt out with autoClose: false. An explicit close() unregisters the hook so a later signal can't close twice.
  • NonRecoverableError. Dead-letters a job immediately instead of burning the remaining maxAttempts. The fail Lua script takes a new noRetry arg.
  • Stale-schema payloads. The worker logs a warning naming the mismatch and throws NonRecoverableError when a job's stored payload no longer validates against the workflow schema (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.
  • README rewritten for the namespace API; repo + package description updated.

Breaking

Settings is no longer exported. Pass logger and redis to WorkflowNamespace instead of Settings.logger / Settings.defaultConnection, and namespace-level metrics via workerOptions.metrics.

Tests

66 pass, including two new ones: NonRecoverableError skipping a 5-attempt budget (verified red before the Lua change), and a stale-schema payload warning + failing without retry. Typecheck, lint and build clean.

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`.
@LouisHaftmann
LouisHaftmann merged commit 4b71e1b into main Jul 30, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant