createWorkerRunner
FunctionSignature
function createWorkerRunner<TJobTypeDefinitions, TStateAdapter, TProcessorsInput, TRequiredAttemptMiddleware>(options): WorkerRunner;core/src/worker/worker-runner.ts:146
Create a worker runner for processing jobs.
Per-attempt configuration (attemptMiddleware, backoffConfig) lives on the processor
registry (see createProcessors). The worker runner dispatches to whichever processor
matches the job's typeName and runs that slice's middleware chain. The worker runner's
backoffConfig is the fallback for processors that don't set their own; precedence is
processor > processor registry > worker runner > built-in default.
The worker runner registers one worker at a time under workerId, a row with a lease it
renews. When the lease is lost, it aborts the attempts' signals, waits for every attempt to
end and registers again under the same id.
Type Parameters
- TJobTypeDefinitionsextends
BaseJobTypeDefinitions - TStateAdapterextends
StateAdapter<any,any,any,Mode> - TProcessorsInputextends |
Processors|readonly Processors[]defaultProcessors - TRequiredAttemptMiddlewareextends readonly
AnyAttemptMiddleware[]defaultreadonly []
Parameters
- options
objectWorker runner configuration. - options.backoffConfig?Backoff for failed job attempts of processors that don't set their own
backoffConfig. - options.client
Client<TJobTypeDefinitions,TStateAdapter>The Queuert client to process jobs for. - options.concurrency?
numberMaximum number of jobs to process in parallel. Must be a positive integer. - options.leaseConfig?The lease the worker runner registers its worker with. Both fields are required when it is passed.
- options.pollIntervalMs?
numberHow often to poll for new jobs when no notify adapter wakes the worker. Must be finite and positive. - options.processors[
ExtraProcessorTypeNames<WorkerProcessorDefs<TProcessorsInput>,TJobTypeDefinitions>] extends [never] ?ValidateRequiredMiddleware<TProcessorsInput,TRequiredAttemptMiddleware> &( TProcessorsInputextends readonlyProcessors[] ?numberextendsTProcessorsInput["length"] ?unknown:ValidatedProcessorSlices<TProcessorsInput> :unknown) :`Error: processors contain job types unknown to the client: ${ExtraProcessorTypeNames<WorkerProcessorDefs<TProcessorsInput>, TJobTypeDefinitions> & string}`A singleProcessors(from createProcessors, pickProcessors or omitProcessors), or an array of slices to merge. Slices must not share job types: an overlap is a type error when the array's length is known at compile time, and throws DuplicateJobTypeError at runtime. - options.recoveryBackoffConfig?Backoff after a failed worker loop iteration, a failed registration or a lost lease. It resets once the worker starts a job.
- options.requiredAttemptMiddleware?
TRequiredAttemptMiddleware&readonly AttemptMiddleware<NoInfer<TStateAdapter>,any>[]Middleware every processor's slice must include, in this order. The worker runner does not run it. - options.workerId?
GetStateAdapterWorkerId<TStateAdapter>Id the worker registers under, kept when it registers again after a lost lease. Pass a fixed id to keep it across process restarts. While a live worker holds it, the worker runner waits for that lease to expire before it starts.
Returns
Throws
- When
concurrency,pollIntervalMs,recoveryBackoffConfig,leaseConfig,backoffConfigor any processor'sbackoffConfigholds an invalid value; the message lists every invalid field. - InvalidWorkerIdError if
workerIdfails the state adapter'svalidateWorkerId. - DuplicateJobTypeError if slices in a
processorsarray share job types. - if a processor's slice is missing
requiredAttemptMiddlewareor has it out of order.