11import type { RedisClient } from 'bun'
2- import type { QueueConfig , JobOptions , PriorityLevel , PriorityQueueOptions , JobStatus } from './types '
3- import { DEFAULT_PRIORITY_LEVEL , MAX_PRIORITY_LEVELS } from './types'
2+ import type { JobEvents } from './events '
3+ import type { JobOptions , JobStatus , PriorityLevel , PriorityQueueOptions , QueueConfig } from './types'
44import { Job } from './job'
5- import { Queue } from './queue'
65import { createLogger } from './logger'
7- import { generateId , getRedisClient , mergeOptions } from './utils '
8- import { Worker } from './worker '
9- import { JobEvents } from './events '
6+ import { Queue } from './queue '
7+ import { DEFAULT_PRIORITY_LEVEL , MAX_PRIORITY_LEVELS } from './types '
8+ import { generateId } from './utils '
109
1110/**
1211 * PriorityQueue implements a queue with priority support
@@ -98,15 +97,24 @@ export class PriorityQueue<T = any> {
9897 // Store the job data with priority
9998 await this . redisClient . send ( 'HMSET' , [
10099 jobKey ,
101- 'id' , jobId ,
102- 'name' , this . name ,
103- 'data' , JSON . stringify ( data ) ,
104- 'timestamp' , timestamp . toString ( ) ,
105- 'delay' , ( opts . delay || 0 ) . toString ( ) ,
106- 'opts' , JSON . stringify ( opts ) ,
107- 'attemptsMade' , '0' ,
108- 'progress' , '0' ,
109- 'priority' , priority . toString ( ) ,
100+ 'id' ,
101+ jobId ,
102+ 'name' ,
103+ this . name ,
104+ 'data' ,
105+ JSON . stringify ( data ) ,
106+ 'timestamp' ,
107+ timestamp . toString ( ) ,
108+ 'delay' ,
109+ ( opts . delay || 0 ) . toString ( ) ,
110+ 'opts' ,
111+ JSON . stringify ( opts ) ,
112+ 'attemptsMade' ,
113+ '0' ,
114+ 'progress' ,
115+ '0' ,
116+ 'priority' ,
117+ priority . toString ( ) ,
110118 ] )
111119
112120 // Handle dependencies if any
@@ -283,7 +291,7 @@ export class PriorityQueue<T = any> {
283291 for ( let priority = 0 ; priority < this . priorityLevels ; priority ++ ) {
284292 const priorityKey = this . getPriorityKey ( priority )
285293 const countResult = await this . redisClient . send ( 'LLEN' , [ priorityKey ] )
286- const count = typeof countResult === 'string' ? parseInt ( countResult , 10 ) : Number ( countResult )
294+ const count = typeof countResult === 'string' ? Number . parseInt ( countResult , 10 ) : Number ( countResult )
287295 priorityJobs += count
288296 }
289297
@@ -319,7 +327,7 @@ export class PriorityQueue<T = any> {
319327
320328 // See if there are any jobs in this priority queue
321329 const lengthResult = await this . redisClient . send ( 'LLEN' , [ priorityKey ] )
322- const length = typeof lengthResult === 'string' ? parseInt ( lengthResult , 10 ) : Number ( lengthResult )
330+ const length = typeof lengthResult === 'string' ? Number . parseInt ( lengthResult , 10 ) : Number ( lengthResult )
323331
324332 if ( length && length > 0 ) {
325333 // Get all jobs from this priority level
@@ -350,13 +358,13 @@ export class PriorityQueue<T = any> {
350358 private startJobMover ( ) : void {
351359 // Move jobs immediately to start
352360 this . moveJobsToWaiting ( ) . catch ( err =>
353- this . logger . error ( `Error moving priority jobs to waiting: ${ ( err as Error ) . message } ` )
361+ this . logger . error ( `Error moving priority jobs to waiting: ${ ( err as Error ) . message } ` ) ,
354362 )
355363
356364 // Then set up interval to do it periodically (faster than the worker tick)
357365 this . jobMoverTimer = setInterval ( ( ) => {
358366 this . moveJobsToWaiting ( ) . catch ( err =>
359- this . logger . error ( `Error moving priority jobs to waiting: ${ ( err as Error ) . message } ` )
367+ this . logger . error ( `Error moving priority jobs to waiting: ${ ( err as Error ) . message } ` ) ,
360368 )
361369 } , 25 ) // Faster than the standard worker tick (50ms)
362370 }
@@ -458,4 +466,4 @@ export class PriorityQueue<T = any> {
458466 private getPriorityKey ( priority : PriorityLevel ) : string {
459467 return `${ this . keyPrefix } :priority:${ priority } `
460468 }
461- }
469+ }
0 commit comments