Task
queue.task registration and per-task configuration.
queue.task registration and per-task configuration.
queue.task(name: string, fn: (...args) => R | Promise<R>, options?: TaskOptions): QueueRegisters a task and returns the queue (chainable) so enqueue can infer each
task's argument types from successive .task() calls. fn may be sync or
async; its return value becomes the job result. Re-registering a name
replaces the function and options.
TaskOptions| Field | Type | Description |
|---|---|---|
maxRetries | number | Attempts before dead-lettering. |
retryBackoff | { baseMs, maxMs } | Exponential backoff bounds. |
retryOn | (error) => boolean | Classifies a thrown error; false dead-letters it immediately. |
timeoutMs | number | Per-attempt timeout. |
maxConcurrent | number | Max simultaneous running jobs of this task. |
rateLimit | `"100/m"` | Rate limit as count/unit, unit s | m | h. |
circuitBreaker | { threshold, windowMs, cooldownMs } | Trip after repeated failures. |
inject | string[] | Resource names injected as a trailing deps argument. See Dependency injection. |
codecs | string[] | Names of registered payload codecs applied to this task's payload only. |
queue.task("add", (a: number, b: number) => a + b, {
maxRetries: 3,
retryBackoff: { baseMs: 1000, maxMs: 60_000 },
timeoutMs: 30_000,
maxConcurrent: 4,
});See the Tasks guide for usage, and Reliability for the semantics of each field.