Skip to content

Commit 839f42e

Browse files
committed
feat: add job retention types
1 parent 69f9f39 commit 839f42e

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export { QueueManager } from './src/queue_manager.js'
44
export { Locator } from './src/locator.js'
55
export { Schedule } from './src/schedule.js'
66
export { ScheduleBuilder } from './src/schedule_builder.js'
7+
export type { AdapterFactory, JobFactory } from './src/types/main.js'
78
export {
89
customBackoff,
910
linearBackoff,

src/types/main.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ export type { Logger }
1919
*/
2020
export type Duration = number | string
2121

22+
/**
23+
* Retention policy for completed/failed jobs.
24+
*
25+
* - `true` (default): Remove job immediately
26+
* - `false`: Keep job in history indefinitely
27+
* - `{ age?, count? }`: Keep with pruning by age and/or count
28+
*/
29+
export type JobRetention = boolean | { age?: Duration; count?: number }
30+
31+
/**
32+
* Possible statuses for a job in the queue.
33+
*/
34+
export type JobStatus = 'pending' | 'active' | 'delayed' | 'completed' | 'failed'
35+
2236
/**
2337
* Result returned when dispatching a job.
2438
*
@@ -78,6 +92,20 @@ export interface JobData {
7892
stalledCount?: number
7993
}
8094

95+
/**
96+
* Record of a job's current state, including history for completed/failed jobs.
97+
*/
98+
export interface JobRecord {
99+
/** Current status of the job */
100+
status: JobStatus
101+
/** Original job data */
102+
data: JobData
103+
/** Timestamp when the job finished (for completed/failed jobs) */
104+
finishedAt?: number
105+
/** Error message (for failed jobs) */
106+
error?: string
107+
}
108+
81109
/**
82110
* Static options for a Job class.
83111
*
@@ -150,6 +178,8 @@ export interface JobOptions {
150178
* @default true
151179
*/
152180
failOnTimeout?: boolean
181+
removeOnComplete?: JobRetention
182+
removeOnFail?: JobRetention
153183
}
154184

155185
/**
@@ -244,6 +274,7 @@ export interface BackoffConfig {
244274
export interface QueueConfig {
245275
adapter?: string
246276
retry?: any
277+
defaultJobOptions?: JobOptions
247278
}
248279

249280
export interface WorkerConfig {
@@ -416,6 +447,7 @@ export interface QueueManagerConfig {
416447
default: string
417448
adapters: Record<string, AdapterFactory>
418449
retry?: RetryConfig
450+
defaultJobOptions?: JobOptions
419451
queues?: Record<string, QueueConfig>
420452
worker?: WorkerConfig
421453
locations?: string[]

0 commit comments

Comments
 (0)