@@ -16,6 +16,9 @@ npm install @boringnode/queue
1616- ** Multiple Queues** : Organize jobs into different queues for better organization
1717- ** Worker Management** : Process jobs with configurable concurrency
1818- ** Auto-Discovery** : Automatically discover and register jobs from specified locations
19+ - ** Priority Queues** : Process high-priority jobs first
20+ - ** Retry with Backoff** : Automatic retries with exponential, linear, or fixed backoff strategies
21+ - ** Job Timeout** : Automatically fail or retry jobs that exceed a time limit
1922
2023## Quick Start
2124
@@ -134,6 +137,10 @@ Configure individual jobs with the `options` property:
134137static options : JobOptions = {
135138 queue: ' email' , // Queue name (default: 'default')
136139 adapter: ' redis' , // Override default adapter
140+ priority: 1 , // Lower number = higher priority (default: 5)
141+ maxRetries: 3 , // Maximum retry attempts
142+ timeout: ' 30s' , // Job timeout duration
143+ failOnTimeout: true , // Fail permanently on timeout (default: false, will retry)
137144}
138145```
139146
@@ -194,6 +201,87 @@ await SendEmailJob.dispatch(payload).in('2h') // 2 hours
194201await SendEmailJob .dispatch (payload ).in (' 1d' ) // 1 day
195202```
196203
204+ ## Priority
205+
206+ Jobs with lower priority numbers are processed first:
207+
208+ ``` typescript
209+ export default class UrgentJob extends Job <Payload > {
210+ static readonly jobName = ' UrgentJob'
211+
212+ static options: JobOptions = {
213+ priority: 1 , // Processed before default priority (5)
214+ }
215+
216+ async execute(): Promise <void > {
217+ // ...
218+ }
219+ }
220+ ```
221+
222+ ## Retry and Backoff
223+
224+ Configure automatic retries with backoff strategies:
225+
226+ ``` typescript
227+ import { exponentialBackoff , linearBackoff , fixedBackoff } from ' @boringnode/queue'
228+
229+ export default class ReliableJob extends Job <Payload > {
230+ static readonly jobName = ' ReliableJob'
231+
232+ static options: JobOptions = {
233+ maxRetries: 5 ,
234+ retry: {
235+ backoff : () => exponentialBackoff ({
236+ baseDelay: ' 1s' ,
237+ maxDelay: ' 1m' ,
238+ multiplier: 2 ,
239+ jitter: true ,
240+ }),
241+ },
242+ }
243+
244+ async execute(): Promise <void > {
245+ // ...
246+ }
247+ }
248+ ```
249+
250+ Available backoff strategies:
251+
252+ - ` exponentialBackoff({ baseDelay, maxDelay, multiplier, jitter }) ` - Exponential increase
253+ - ` linearBackoff({ baseDelay, maxDelay, multiplier }) ` - Linear increase
254+ - ` fixedBackoff({ baseDelay, jitter }) ` - Fixed delay between retries
255+
256+ ## Job Timeout
257+
258+ Set a maximum execution time for jobs:
259+
260+ ``` typescript
261+ export default class LimitedJob extends Job <Payload > {
262+ static readonly jobName = ' LimitedJob'
263+
264+ static options: JobOptions = {
265+ timeout: ' 30s' , // Maximum execution time
266+ failOnTimeout: false , // Retry on timeout (default)
267+ }
268+
269+ async execute(): Promise <void > {
270+ // Long running operation...
271+ }
272+ }
273+ ```
274+
275+ You can also set a global timeout in the worker configuration:
276+
277+ ``` typescript
278+ const config = {
279+ worker: {
280+ timeout: ' 1m' , // Default timeout for all jobs
281+ },
282+ }
283+ ```
284+
197285## Job Discovery
198286
199287The queue manager automatically discovers and registers jobs from the specified locations:
0 commit comments