@@ -15,7 +15,7 @@ import {
15
15
RedisClient ,
16
16
WorkerOptions ,
17
17
} from '../interfaces' ;
18
- import { MinimalQueue } from '../types' ;
18
+ import { MinimalQueue , Serialize } from '../types' ;
19
19
import {
20
20
delay ,
21
21
DELAY_TIME_1 ,
@@ -55,7 +55,7 @@ export interface WorkerListener<
55
55
*
56
56
* This event is triggered when a job enters the 'active' state.
57
57
*/
58
- active : ( job : Job < DataType , ResultType , NameType > , prev : string ) => void ;
58
+ active : ( job : Job < Serialize < DataType > , ResultType , NameType > , prev : string ) => void ;
59
59
60
60
/**
61
61
* Listen to 'closing' event.
@@ -77,7 +77,7 @@ export interface WorkerListener<
77
77
* This event is triggered when a job has successfully completed.
78
78
*/
79
79
completed : (
80
- job : Job < DataType , ResultType , NameType > ,
80
+ job : Job < Serialize < DataType > , ResultType , NameType > ,
81
81
result : ResultType ,
82
82
prev : string ,
83
83
) => void ;
@@ -106,7 +106,7 @@ export interface WorkerListener<
106
106
* reaches the stalled limit and it is deleted by the removeOnFail option.
107
107
*/
108
108
failed : (
109
- job : Job < DataType , ResultType , NameType > | undefined ,
109
+ job : Job < Serialize < DataType > , ResultType , NameType > | undefined ,
110
110
error : Error ,
111
111
prev : string ,
112
112
) => void ;
@@ -127,7 +127,7 @@ export interface WorkerListener<
127
127
* world.
128
128
*/
129
129
progress : (
130
- job : Job < DataType , ResultType , NameType > ,
130
+ job : Job < Serialize < DataType > , ResultType , NameType > ,
131
131
progress : number | object ,
132
132
) => void ;
133
133
@@ -171,7 +171,7 @@ export class Worker<
171
171
172
172
private abortDelayController : AbortController | null = null ;
173
173
private asyncFifoQueue : AsyncFifoQueue < void | Job <
174
- DataType ,
174
+ Serialize < DataType > ,
175
175
ResultType ,
176
176
NameType
177
177
> > ;
@@ -187,7 +187,7 @@ export class Worker<
187
187
private _repeat : Repeat ;
188
188
189
189
protected paused : Promise < void > ;
190
- protected processFn : Processor < DataType , ResultType , NameType > ;
190
+ protected processFn : Processor < Serialize < DataType > , ResultType , NameType > ;
191
191
protected running = false ;
192
192
193
193
static RateLimitError ( ) : Error {
@@ -196,7 +196,7 @@ export class Worker<
196
196
197
197
constructor (
198
198
name : string ,
199
- processor ?: string | URL | null | Processor < DataType , ResultType , NameType > ,
199
+ processor ?: string | URL | null | Processor < Serialize < DataType > , ResultType , NameType > ,
200
200
opts ?: WorkerOptions ,
201
201
Connection ?: typeof RedisConnection ,
202
202
) {
@@ -289,7 +289,7 @@ export class Worker<
289
289
useWorkerThreads : this . opts . useWorkerThreads ,
290
290
} ) ;
291
291
292
- this . processFn = sandbox < DataType , ResultType , NameType > (
292
+ this . processFn = sandbox < Serialize < DataType > , ResultType , NameType > (
293
293
processor ,
294
294
this . childPool ,
295
295
) . bind ( this ) ;
@@ -348,7 +348,7 @@ export class Worker<
348
348
}
349
349
350
350
protected callProcessJob (
351
- job : Job < DataType , ResultType , NameType > ,
351
+ job : Job < Serialize < DataType > , ResultType , NameType > ,
352
352
token : string ,
353
353
) : Promise < ResultType > {
354
354
return this . processFn ( job , token ) ;
@@ -357,9 +357,9 @@ export class Worker<
357
357
protected createJob (
358
358
data : JobJsonRaw ,
359
359
jobId : string ,
360
- ) : Job < DataType , ResultType , NameType > {
360
+ ) : Job < Serialize < DataType > , ResultType , NameType > {
361
361
return this . Job . fromJSON ( this as MinimalQueue , data , jobId ) as Job <
362
- DataType ,
362
+ Serialize < DataType > ,
363
363
ResultType ,
364
364
NameType
365
365
> ;
@@ -423,7 +423,7 @@ export class Worker<
423
423
this . startLockExtenderTimer ( jobsInProgress ) ;
424
424
425
425
const asyncFifoQueue = ( this . asyncFifoQueue =
426
- new AsyncFifoQueue < void | Job < DataType , ResultType , NameType > > ( ) ) ;
426
+ new AsyncFifoQueue < void | Job < Serialize < DataType > , ResultType , NameType > > ( ) ) ;
427
427
428
428
let tokenPostfix = 0 ;
429
429
@@ -450,7 +450,7 @@ export class Worker<
450
450
const token = `${ this . id } :${ tokenPostfix ++ } ` ;
451
451
452
452
const fetchedJob = this . retryIfFailed < void | Job <
453
- DataType ,
453
+ Serialize < DataType > ,
454
454
ResultType ,
455
455
NameType
456
456
> > (
@@ -484,18 +484,18 @@ export class Worker<
484
484
485
485
// Since there can be undefined jobs in the queue (when a job fails or queue is empty)
486
486
// we iterate until we find a job.
487
- let job : Job < DataType , ResultType , NameType > | void ;
487
+ let job : Job < Serialize < DataType > , ResultType , NameType > | void ;
488
488
do {
489
489
job = await asyncFifoQueue . fetch ( ) ;
490
490
} while ( ! job && asyncFifoQueue . numQueued ( ) > 0 ) ;
491
491
492
492
if ( job ) {
493
493
const token = job . token ;
494
494
asyncFifoQueue . add (
495
- this . retryIfFailed < void | Job < DataType , ResultType , NameType > > (
495
+ this . retryIfFailed < void | Job < Serialize < DataType > , ResultType , NameType > > (
496
496
( ) =>
497
497
this . processJob (
498
- < Job < DataType , ResultType , NameType > > job ,
498
+ < Job < Serialize < DataType > , ResultType , NameType > > job ,
499
499
token ,
500
500
( ) => asyncFifoQueue . numTotal ( ) <= this . opts . concurrency ,
501
501
jobsInProgress ,
@@ -533,7 +533,7 @@ export class Worker<
533
533
bclient : RedisClient ,
534
534
token : string ,
535
535
{ block = true } : GetNextJobOptions = { } ,
536
- ) : Promise < Job < DataType , ResultType , NameType > | undefined > {
536
+ ) : Promise < Job < Serialize < DataType > , ResultType , NameType > | undefined > {
537
537
if ( this . paused ) {
538
538
if ( block ) {
539
539
await this . paused ;
@@ -608,7 +608,7 @@ will never work with more accuracy than 1ms. */
608
608
client : RedisClient ,
609
609
token : string ,
610
610
name ?: string ,
611
- ) : Promise < Job < DataType , ResultType , NameType > > {
611
+ ) : Promise < Job < Serialize < DataType > , ResultType , NameType > > {
612
612
const [ jobData , id , limitUntil , delayUntil ] =
613
613
await this . scripts . moveToActive ( client , token , name ) ;
614
614
this . updateDelays ( limitUntil , delayUntil ) ;
@@ -719,7 +719,7 @@ will never work with more accuracy than 1ms. */
719
719
jobData ?: JobJsonRaw ,
720
720
jobId ?: string ,
721
721
token ?: string ,
722
- ) : Promise < Job < DataType , ResultType , NameType > > {
722
+ ) : Promise < Job < Serialize < DataType > , ResultType , NameType > > {
723
723
if ( ! jobData ) {
724
724
if ( ! this . drained ) {
725
725
this . emit ( 'drained' ) ;
@@ -740,11 +740,11 @@ will never work with more accuracy than 1ms. */
740
740
}
741
741
742
742
async processJob (
743
- job : Job < DataType , ResultType , NameType > ,
743
+ job : Job < Serialize < DataType > , ResultType , NameType > ,
744
744
token : string ,
745
745
fetchNextCallback = ( ) => true ,
746
746
jobsInProgress : Set < { job : Job ; ts : number } > ,
747
- ) : Promise < void | Job < DataType , ResultType , NameType > > {
747
+ ) : Promise < void | Job < Serialize < DataType > , ResultType , NameType > > {
748
748
if ( ! job || this . closing || this . paused ) {
749
749
return ;
750
750
}
@@ -1051,10 +1051,10 @@ will never work with more accuracy than 1ms. */
1051
1051
1052
1052
stalled . forEach ( ( jobId : string ) => this . emit ( 'stalled' , jobId , 'active' ) ) ;
1053
1053
1054
- const jobPromises : Promise < Job < DataType , ResultType , NameType > > [ ] = [ ] ;
1054
+ const jobPromises : Promise < Job < Serialize < DataType > , ResultType , NameType > > [ ] = [ ] ;
1055
1055
for ( let i = 0 ; i < failed . length ; i ++ ) {
1056
1056
jobPromises . push (
1057
- Job . fromId < DataType , ResultType , NameType > (
1057
+ Job . fromId < Serialize < DataType > , ResultType , NameType > (
1058
1058
this as MinimalQueue ,
1059
1059
failed [ i ] ,
1060
1060
) ,
@@ -1069,8 +1069,8 @@ will never work with more accuracy than 1ms. */
1069
1069
this . notifyFailedJobs ( await Promise . all ( jobPromises ) ) ;
1070
1070
}
1071
1071
1072
- private notifyFailedJobs ( failedJobs : Job < DataType , ResultType , NameType > [ ] ) {
1073
- failedJobs . forEach ( ( job : Job < DataType , ResultType , NameType > ) =>
1072
+ private notifyFailedJobs ( failedJobs : Job < Serialize < DataType > , ResultType , NameType > [ ] ) {
1073
+ failedJobs . forEach ( ( job : Job < Serialize < DataType > , ResultType , NameType > ) =>
1074
1074
this . emit (
1075
1075
'failed' ,
1076
1076
job ,
@@ -1081,7 +1081,7 @@ will never work with more accuracy than 1ms. */
1081
1081
}
1082
1082
1083
1083
private moveLimitedBackToWait (
1084
- job : Job < DataType , ResultType , NameType > ,
1084
+ job : Job < Serialize < DataType > , ResultType , NameType > ,
1085
1085
token : string ,
1086
1086
) {
1087
1087
return this . scripts . moveJobFromActiveToWait ( job . id , token ) ;
0 commit comments