Skip to content
Français

runQueueWorker

import { runQueueWorker } from "@elie-laloum/outpost";

Claim jobs for the registered handlers and run them one at a time until signal aborts, renewing each lease at every third of leaseMs. A thrown error or a result with error marks the job failed; a lost lease or a cancellation aborts the handler’s signal and stores nothing. Resolves once signal aborts and rejects when a queue operation fails.

Complete example and detailed rules.

  • optionsRequired
    QueueWorkerOptions
    Queue, worker name, handlers, stop signal, and lease and polling timings.
  • options.queueRequired
    TaskQueue
    Queue the worker claims jobs from and reports results to.
  • options.workerRequired
    string
    Worker name recorded on each claimed job, 1 to 512 characters; give each process its own.
  • options.handlersRequired
    Readonly<Record<string, QueueHandler>>
    Handlers by name, 1 to 100; the worker claims only jobs whose handler is listed here.
  • options.signalRequired
    AbortSignal
    Stops the worker: runQueueWorker() resolves and the running handler’s signal aborts. That job stays active until its lease expires.
  • options.leaseMsOptional
    number | undefined
    Lease duration in milliseconds, default 30000, from 30 to 300000; renewed at every third of it.
  • options.pollMsOptional
    number | undefined
    Wait in milliseconds after finding no eligible job, default 250; must be positive.

Promise<void>

export declare function runQueueWorker(
  options: QueueWorkerOptions,
): Promise<void>;