@@ -7,7 +7,6 @@ import { expect } from 'chai';
7
7
import * as IORedis from 'ioredis' ;
8
8
import { beforeEach , describe , it } from 'mocha' ;
9
9
import { v4 } from 'uuid' ;
10
- import { defaults } from 'lodash' ;
11
10
import { removeAllQueueData } from '@src/utils' ;
12
11
13
12
const sinon = require ( 'sinon' ) ;
@@ -158,7 +157,7 @@ describe('repeat', function() {
158
157
let prev : any ;
159
158
var counter = 0 ;
160
159
161
- const completting = new Promise ( resolve => {
160
+ const completting = new Promise < void > ( resolve => {
162
161
worker . on ( 'completed' , async job => {
163
162
this . clock . tick ( nextTick ) ;
164
163
if ( prev ) {
@@ -206,7 +205,7 @@ describe('repeat', function() {
206
205
let prev : Job ;
207
206
let counter = 0 ;
208
207
209
- const completting = new Promise ( ( resolve , reject ) => {
208
+ const completting = new Promise < void > ( ( resolve , reject ) => {
210
209
worker . on ( 'completed' , async job => {
211
210
this . clock . tick ( nextTick ) ;
212
211
if ( prev ) {
@@ -255,7 +254,7 @@ describe('repeat', function() {
255
254
let prev : Job ;
256
255
let counter = 0 ;
257
256
258
- const completting = new Promise ( ( resolve , reject ) => {
257
+ const completting = new Promise < void > ( ( resolve , reject ) => {
259
258
worker . on ( 'completed' , async job => {
260
259
this . clock . tick ( nextTick ) ;
261
260
if ( prev ) {
@@ -300,7 +299,7 @@ describe('repeat', function() {
300
299
301
300
let prev : Job ;
302
301
let counter = 0 ;
303
- const completting = new Promise ( ( resolve , reject ) => {
302
+ const completting = new Promise < void > ( ( resolve , reject ) => {
304
303
queue . on ( 'completed' , async job => {
305
304
this . clock . tick ( nextTick ) ;
306
305
if ( prev ) {
@@ -400,7 +399,7 @@ describe('repeat', function() {
400
399
const repeat = { cron : '*/1 * * * * *' } ;
401
400
let processor ;
402
401
403
- const processing = new Promise ( ( resolve , reject ) => {
402
+ const processing = new Promise < void > ( ( resolve , reject ) => {
404
403
processor = async ( job : Job ) => {
405
404
counter ++ ;
406
405
if ( counter == numJobs ) {
@@ -410,7 +409,7 @@ describe('repeat', function() {
410
409
expect ( delayed ) . to . be . empty ;
411
410
resolve ( ) ;
412
411
} else if ( counter > numJobs ) {
413
- reject ( Error ( ' should not repeat more than 7 times' ) ) ;
412
+ reject ( Error ( ` should not repeat more than ${ numJobs } times` ) ) ;
414
413
}
415
414
} ;
416
415
} ) ;
@@ -449,6 +448,7 @@ describe('repeat', function() {
449
448
const queueScheduler = new QueueScheduler ( queueName ) ;
450
449
await queueScheduler . waitUntilReady ( ) ;
451
450
451
+ const numJobs = 4 ;
452
452
const date = new Date ( '2017-02-07 9:24:00' ) ;
453
453
let prev : Job ;
454
454
let counter = 0 ;
@@ -464,10 +464,10 @@ describe('repeat', function() {
464
464
465
465
this . clock . tick ( nextTick ) ;
466
466
467
- const processing = new Promise ( ( resolve , reject ) => {
467
+ const processing = new Promise < void > ( ( resolve , reject ) => {
468
468
processor = async ( job : Job ) => {
469
469
counter ++ ;
470
- if ( counter == 4 ) {
470
+ if ( counter == numJobs ) {
471
471
try {
472
472
await queue . removeRepeatable ( 'test' , repeat , jobId ) ;
473
473
this . clock . tick ( nextTick ) ;
@@ -477,8 +477,8 @@ describe('repeat', function() {
477
477
} catch ( err ) {
478
478
reject ( err ) ;
479
479
}
480
- } else if ( counter > 4 ) {
481
- reject ( Error ( ' should not repeat more than 4 times' ) ) ;
480
+ } else if ( counter > numJobs ) {
481
+ reject ( Error ( ` should not repeat more than ${ numJobs } times` ) ) ;
482
482
}
483
483
} ;
484
484
} ) ;
@@ -509,21 +509,21 @@ describe('repeat', function() {
509
509
const jobId = 'xxxx' ;
510
510
const date = new Date ( '2017-02-07 9:24:00' ) ;
511
511
const nextTick = 2 * ONE_SECOND + 100 ;
512
- const nextRepeatableJob = repeat . addNextRepeatableJob ;
513
- this . clock . tick ( date . getTime ( ) ) ;
512
+ const addNextRepeatableJob = repeat . addNextRepeatableJob ;
513
+ this . clock . setSystemTime ( date ) ;
514
514
515
515
const repeatOpts = { cron : '*/2 * * * * *' } ;
516
516
517
- const afterRemoved = new Promise ( async resolve => {
517
+ const afterRemoved = new Promise < void > ( async resolve => {
518
518
worker = new Worker ( queueName , async job => {
519
519
const repeatWorker = await worker . repeat ;
520
520
repeatWorker . addNextRepeatableJob = async ( ...args ) => {
521
521
// In order to simulate race condition
522
522
// Make removeRepeatables happen any time after a moveToX is called
523
- await queue . removeRepeatable ( 'test' , defaults ( { jobId } , repeatOpts ) ) ;
523
+ await queue . removeRepeatable ( 'test' , repeatOpts , jobId ) ;
524
524
525
- // nextRepeatableJob will now re-add the removed repeatable
526
- const result = await nextRepeatableJob . apply ( repeat , args ) ;
525
+ // addNextRepeatableJob will now re-add the removed repeatable
526
+ const result = await addNextRepeatableJob . apply ( repeat , args ) ;
527
527
resolve ( ) ;
528
528
return result ;
529
529
} ;
@@ -604,7 +604,7 @@ describe('repeat', function() {
604
604
605
605
var counter = 0 ;
606
606
607
- const completting = new Promise ( ( resolve , reject ) => {
607
+ const completting = new Promise < void > ( ( resolve , reject ) => {
608
608
worker . on ( 'completed' , ( ) => {
609
609
this . clock . tick ( nextTick ) ;
610
610
counter ++ ;
@@ -630,7 +630,7 @@ describe('repeat', function() {
630
630
631
631
let processor ;
632
632
633
- const processing = new Promise ( ( resolve , reject ) => {
633
+ const processing = new Promise < void > ( ( resolve , reject ) => {
634
634
processor = async ( job : Job ) => {
635
635
try {
636
636
expect ( job . id ) . to . be . ok ;
@@ -685,7 +685,7 @@ describe('repeat', function() {
685
685
let prevType : string ;
686
686
let counter = 0 ;
687
687
688
- const completting = new Promise ( resolve => {
688
+ const completting = new Promise < void > ( resolve => {
689
689
worker . on ( 'completed' , job => {
690
690
this . clock . tick ( nextTick ) ;
691
691
if ( prevType ) {
@@ -729,12 +729,12 @@ describe('repeat', function() {
729
729
730
730
const worker = new Worker ( queueName , async job => { } ) ;
731
731
732
- const waiting = new Promise ( ( resolve , reject ) => {
732
+ const waiting = new Promise < void > ( ( resolve , reject ) => {
733
733
queueEvents . on ( 'waiting' , function ( { jobId } ) {
734
734
try {
735
735
expect ( jobId ) . to . be . equal (
736
- ' repeat:test:16db7a9b166154f5c636abf3c8fe3364:' +
737
- ( date . getTime ( ) + 1 * ONE_SECOND ) ,
736
+ ` repeat:c602b9b36e4beddd9e7db39a3ef2ea4c: ${ date . getTime ( ) +
737
+ 1 * ONE_SECOND } ` ,
738
738
) ;
739
739
resolve ( ) ;
740
740
} catch ( err ) {
@@ -763,7 +763,7 @@ describe('repeat', function() {
763
763
this . clock . tick ( ONE_SECOND + 100 ) ;
764
764
765
765
let processor ;
766
- const processing = new Promise ( ( resolve , reject ) => {
766
+ const processing = new Promise < void > ( ( resolve , reject ) => {
767
767
processor = async ( job : Job ) => {
768
768
if ( job . opts . repeat . count === 1 ) {
769
769
resolve ( ) ;
0 commit comments