@@ -27,7 +27,19 @@ export type Duration = number | string
2727 * - `false`: Keep job in history indefinitely
2828 * - `{ age?, count? }`: Keep with pruning by age and/or count
2929 */
30- export type JobRetention = boolean | { age ?: Duration ; count ?: number }
30+ export type JobRetention =
31+ | boolean
32+ | {
33+ /**
34+ * Keep jobs newer than this duration.
35+ */
36+ age ?: Duration
37+
38+ /**
39+ * Keep at most this many jobs.
40+ */
41+ count ?: number
42+ }
3143
3244/**
3345 * Possible statuses for a job in the queue.
@@ -92,7 +104,7 @@ export interface JobData {
92104 /**
93105 * Job priority (lower = higher priority).
94106 *
95- * @default 0
107+ * @default 5
96108 */
97109 priority ?: number
98110
@@ -186,25 +198,31 @@ export interface JobOptions {
186198
187199 /**
188200 * Adapter name or factory to use for this job.
201+ *
202+ * Defaults to the queue manager's configured default adapter.
189203 */
190204 adapter ?: string | ( ( ) => Adapter )
191205
192206 /**
193207 * Maximum retry attempts before permanent failure.
194208 *
195- * @default 3
209+ * This is a convenience alias for `retry.maxRetries`.
210+ *
211+ * @default 0
196212 */
197213 maxRetries ?: number
198214
199215 /**
200216 * Job priority (lower = higher priority).
201217 *
202- * @default 0
218+ * @default 5
203219 */
204220 priority ?: number
205221
206222 /**
207- * Retry configuration (backoff strategy, delays, etc.).
223+ * Retry configuration for this job.
224+ *
225+ * Overrides queue-level and global retry settings.
208226 */
209227 retry ?: RetryConfig
210228
@@ -218,10 +236,24 @@ export interface JobOptions {
218236 /**
219237 * Whether to mark job as failed on timeout.
220238 *
221- * @default true
239+ * When disabled, timed out jobs follow the normal retry policy.
240+ *
241+ * @default false
222242 */
223243 failOnTimeout ?: boolean
244+
245+ /**
246+ * Retention policy for completed jobs.
247+ *
248+ * By default, completed jobs are removed immediately.
249+ */
224250 removeOnComplete ?: JobRetention
251+
252+ /**
253+ * Retention policy for failed jobs.
254+ *
255+ * By default, failed jobs are removed immediately after the failure hooks run.
256+ */
225257 removeOnFail ?: JobRetention
226258}
227259
@@ -299,27 +331,88 @@ export type JobClass<T extends Job = Job> = (new (...args: unknown[]) => T) & {
299331 */
300332export type JobFactory = ( JobClass : JobClass ) => Job | Promise < Job >
301333
334+ /**
335+ * Retry policy used by jobs, queues, or the queue manager.
336+ */
302337export interface RetryConfig {
338+ /**
339+ * Number of retry attempts after the first failed execution.
340+ *
341+ * Set to `0` to disable retries.
342+ *
343+ * @default 0
344+ */
303345 maxRetries ?: number
346+
347+ /**
348+ * Factory that creates the backoff strategy used between retry attempts.
349+ *
350+ * If omitted, failed jobs are retried as soon as the adapter makes them
351+ * available again.
352+ */
304353 backoff ?: ( ) => BackoffStrategyClass
305354}
306355
356+ /**
357+ * Built-in retry delay algorithms.
358+ */
307359export type BackoffStrategy = 'exponential' | 'linear' | 'fixed'
308360
361+ /**
362+ * Configuration for built-in and custom retry backoff strategies.
363+ */
309364export interface BackoffConfig {
365+ /**
366+ * Strategy used to compute the delay before the next retry.
367+ */
310368 strategy : BackoffStrategy
369+
370+ /**
371+ * Initial delay used by the strategy.
372+ */
311373 baseDelay : Duration
374+
375+ /**
376+ * Upper bound for computed retry delays.
377+ */
312378 maxDelay ?: Duration
379+
380+ /**
381+ * Growth factor for exponential backoff.
382+ */
313383 multiplier ?: number
384+
385+ /**
386+ * Whether to randomize retry delays to avoid retry bursts.
387+ */
314388 jitter ?: boolean
315389}
316390
391+ /**
392+ * Runtime configuration for a named queue.
393+ */
317394export interface QueueConfig {
395+ /**
396+ * Adapter name used by jobs dispatched to this queue.
397+ *
398+ * Falls back to the queue manager's default adapter.
399+ */
318400 adapter ?: string
401+
402+ /**
403+ * Retry policy applied to jobs in this queue unless overridden by job options.
404+ */
319405 retry ?: RetryConfig
406+
407+ /**
408+ * Default job options applied to jobs in this queue unless overridden by the job.
409+ */
320410 defaultJobOptions ?: JobOptions
321411}
322412
413+ /**
414+ * Runtime options for workers that poll queues and execute jobs.
415+ */
323416export interface WorkerConfig {
324417 /**
325418 * Maximum number of jobs to process concurrently.
@@ -376,12 +469,37 @@ export interface WorkerConfig {
376469 onShutdownSignal ?: ( ) => void | Promise < void >
377470}
378471
472+ /**
473+ * Event yielded by the low-level worker processing generator.
474+ */
379475export type WorkerCycle =
380- | { type : 'started' ; queue : string ; job : JobData }
381- | { type : 'completed' ; queue : string ; job : JobData }
382- | { type : 'idle' ; suggestedDelay : Duration }
383- | { type : 'error' ; error : Error ; suggestedDelay : Duration }
476+ | {
477+ /** A job was acquired and execution started. */
478+ type : 'started'
479+ queue : string
480+ job : JobData
481+ }
482+ | {
483+ /** A running job finished, either successfully or after failure handling. */
484+ type : 'completed'
485+ queue : string
486+ job : JobData
487+ }
488+ | {
489+ /** No work was available. Consumers should wait before polling again. */
490+ type : 'idle'
491+ suggestedDelay : Duration
492+ }
493+ | {
494+ /** An unexpected worker loop error occurred. */
495+ type : 'error'
496+ error : Error
497+ suggestedDelay : Duration
498+ }
384499
500+ /**
501+ * Factory used to lazily create adapter instances.
502+ */
385503export type AdapterFactory < T extends Adapter = Adapter > = ( ) => T
386504
387505/**
@@ -487,12 +605,50 @@ export interface ScheduleListOptions {
487605}
488606
489607export interface QueueManagerConfig {
608+ /**
609+ * Name of the adapter used when a job does not select one explicitly.
610+ *
611+ * Must match one of the keys from `adapters`.
612+ */
490613 default : string
614+
615+ /**
616+ * Available queue adapters keyed by name.
617+ *
618+ * Adapters are lazy-instantiated the first time they are used.
619+ */
491620 adapters : Record < string , AdapterFactory >
621+
622+ /**
623+ * Global retry configuration applied to all jobs unless overridden by
624+ * queue-level or job-level options.
625+ */
492626 retry ?: RetryConfig
627+
628+ /**
629+ * Global job options applied to all jobs unless overridden by queue-level
630+ * or job-level options.
631+ */
493632 defaultJobOptions ?: JobOptions
633+
634+ /**
635+ * Per-queue configuration keyed by queue name.
636+ *
637+ * Use this to select adapters or defaults for specific queues.
638+ */
494639 queues ?: Record < string , QueueConfig >
640+
641+ /**
642+ * Worker runtime options used by `Worker` instances.
643+ */
495644 worker ?: WorkerConfig
645+
646+ /**
647+ * Glob patterns used to discover and register job classes.
648+ *
649+ * These locations are used by `init()` when `autoLoadJobs` is enabled,
650+ * and by `QueueManager.loadJobs()` when called without arguments.
651+ */
496652 locations ?: string [ ]
497653
498654 /**
@@ -504,6 +660,12 @@ export interface QueueManagerConfig {
504660 * @default true
505661 */
506662 autoLoadJobs ?: boolean
663+
664+ /**
665+ * Logger used by the queue runtime.
666+ *
667+ * Defaults to the console logger.
668+ */
507669 logger ?: Logger
508670
509671 /**
0 commit comments