Skip to content

Commit c12654a

Browse files
committed
docs: improve JSDoc documentation for types with default values
1 parent 5283833 commit c12654a

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

src/types/main.ts

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ import { Job } from '../job.js'
55

66
export type { Logger }
77

8+
/**
9+
* Duration can be specified as milliseconds (number) or as a human-readable string.
10+
*
11+
* Supported string formats: '1s', '5m', '2h', '1d', etc.
12+
*
13+
* @example
14+
* ```typescript
15+
* const timeout: Duration = '30s' // 30 seconds
16+
* const delay: Duration = 5000 // 5000 milliseconds
17+
* const interval: Duration = '5m' // 5 minutes
18+
* ```
19+
*/
820
export type Duration = number | string
921

1022
/**
@@ -21,23 +33,112 @@ export interface DispatchResult {
2133
jobId: string
2234
}
2335

36+
/**
37+
* Internal representation of a job in the queue.
38+
*
39+
* This is used by adapters to store and retrieve job data.
40+
* Not typically used directly by application code.
41+
*/
2442
export interface JobData {
43+
/**
44+
* Unique identifier for this job.
45+
*/
2546
id: string
47+
48+
/**
49+
* Job class name.
50+
*/
2651
name: string
52+
53+
/**
54+
* Serialized job payload.
55+
*/
2756
payload: any
57+
58+
/**
59+
* Number of execution attempts so far.
60+
*/
2861
attempts: number
62+
63+
/**
64+
* Job priority (lower = higher priority).
65+
*
66+
* @default 0
67+
*/
2968
priority?: number
69+
70+
/**
71+
* When to retry this job next (for failed jobs).
72+
*/
3073
nextRetryAt?: Date
74+
75+
/**
76+
* Number of times this job was recovered from stalled state.
77+
*/
3178
stalledCount?: number
3279
}
3380

81+
/**
82+
* Static options for a Job class.
83+
*
84+
* Define these as a static property on your Job class to configure
85+
* default behavior for all instances.
86+
*
87+
* @example
88+
* ```typescript
89+
* class SendEmailJob extends Job<EmailPayload> {
90+
* static options: JobOptions = {
91+
* queue: 'emails',
92+
* maxRetries: 3,
93+
* timeout: '30s',
94+
* }
95+
* }
96+
* ```
97+
*/
3498
export interface JobOptions {
99+
/**
100+
* Queue name for this job.
101+
*
102+
* @default 'default'
103+
*/
35104
queue?: string
105+
106+
/**
107+
* Adapter name or factory to use for this job.
108+
*/
36109
adapter?: string | (() => Adapter)
110+
111+
/**
112+
* Maximum retry attempts before permanent failure.
113+
*
114+
* @default 3
115+
*/
37116
maxRetries?: number
117+
118+
/**
119+
* Job priority (lower = higher priority).
120+
*
121+
* @default 0
122+
*/
38123
priority?: number
124+
125+
/**
126+
* Retry configuration (backoff strategy, delays, etc.).
127+
*/
39128
retry?: RetryConfig
129+
130+
/**
131+
* Maximum execution time before timeout.
132+
*
133+
* @default undefined (no timeout)
134+
*/
40135
timeout?: Duration
136+
137+
/**
138+
* Whether to mark job as failed on timeout.
139+
*
140+
* @default true
141+
*/
41142
failOnTimeout?: boolean
42143
}
43144

0 commit comments

Comments
 (0)