Skip to content

AttemptMiddleware

AttemptMiddleware<TStateAdapter, THandlerCtx, TPrepareCtx, TStepCtx, TCompleteCtx> = object

Defined in: packages/core/src/worker/attempt-middleware.ts:38

Wraps job processing with cross-cutting logic for one or more phases.

Each hook is optional — implement only the phases you need. The next(ctx) callback injects typed context that becomes available to the inner handler:

  • wrapHandler — wraps the entire attempt handler. Injected ctx is merged into attemptHandler’s options.
  • wrapPrepare — wraps the user-supplied prepare callback. Injected ctx is merged into the callback’s options alongside the transaction context.
  • wrapStep — wraps each user-supplied step callback. Injected ctx is merged into the callback’s options alongside transactionHooks and the transaction context.
  • wrapComplete — wraps the user-supplied complete callback. Injected ctx is merged into the callback’s options alongside finish, transactionHooks, and the transaction context.

Multiple middleware compose as an onion — the first middleware’s “before” runs outermost. Each next(ctx) accumulates ctx for inner layers.

TStateAdapter extends StateAdapter<any, any>

THandlerCtx extends Record<string, unknown> = Record<string, unknown>

TPrepareCtx extends Record<string, unknown> = Record<string, unknown>

TStepCtx extends Record<string, unknown> = Record<string, unknown>

TCompleteCtx extends Record<string, unknown> = Record<string, unknown>

optional wrapComplete?: <T>(opts) => Promise<T>

Defined in: packages/core/src/worker/attempt-middleware.ts:63

T

object & GetStateAdapterTxContext<TStateAdapter>

Promise<T>


optional wrapHandler?: <T>(opts) => Promise<T>

Defined in: packages/core/src/worker/attempt-middleware.ts:45

T

RunningJob<TStateAdapter>

(ctx) => Promise<T>

string

Promise<T>


optional wrapPrepare?: <T>(opts) => Promise<T>

Defined in: packages/core/src/worker/attempt-middleware.ts:50

T

object & GetStateAdapterTxContext<TStateAdapter>

Promise<T>


optional wrapStep?: <T>(opts) => Promise<T>

Defined in: packages/core/src/worker/attempt-middleware.ts:56

T

object & GetStateAdapterTxContext<TStateAdapter>

Promise<T>