@@ -93,19 +93,19 @@ export class JobScheduler extends QueueBase {
93
93
}
94
94
95
95
let nextMillis : number ;
96
- let newOffset = offset || 0 ;
96
+ let newOffset = 0 ;
97
97
98
98
if ( every ) {
99
99
const prevSlot = Math . floor ( startMillis / every ) * every ;
100
100
const nextSlot = prevSlot + every ;
101
- if ( prevMillis || offset ) {
101
+ newOffset = startMillis - prevSlot ;
102
+ // newOffset should always be positive, but we do an extra safety check
103
+ newOffset = newOffset < 0 ? 0 : newOffset ;
104
+
105
+ if ( prevMillis ) {
102
106
nextMillis = nextSlot ;
103
107
} else {
104
108
nextMillis = prevSlot ;
105
- newOffset = startMillis - prevSlot ;
106
-
107
- // newOffset should always be positive, but we do an extra safety check
108
- newOffset = newOffset < 0 ? 0 : newOffset ;
109
109
}
110
110
} else if ( pattern ) {
111
111
nextMillis = await this . repeatStrategy ( now , repeatOpts , jobName ) ;
@@ -246,7 +246,6 @@ export class JobScheduler extends QueueBase {
246
246
mergedOpts . repeat = {
247
247
...opts . repeat ,
248
248
count : currentCount ,
249
- offset,
250
249
endDate : opts . repeat ?. endDate
251
250
? new Date ( opts . repeat . endDate ) . getTime ( )
252
251
: undefined ,
@@ -255,51 +254,6 @@ export class JobScheduler extends QueueBase {
255
254
return mergedOpts ;
256
255
}
257
256
258
- private createNextJob < T = any , R = any , N extends string = string > (
259
- client : RedisClient ,
260
- name : N ,
261
- nextMillis : number ,
262
- offset : number ,
263
- jobSchedulerId : string ,
264
- opts : JobsOptions ,
265
- data : T ,
266
- currentCount : number ,
267
- // The job id of the job that produced this next iteration
268
- producerId ?: string ,
269
- ) {
270
- //
271
- // Generate unique job id for this iteration.
272
- //
273
- const jobId = this . getSchedulerNextJobId ( {
274
- jobSchedulerId,
275
- nextMillis,
276
- } ) ;
277
-
278
- const now = Date . now ( ) ;
279
- const delay = nextMillis + offset - now ;
280
-
281
- const mergedOpts = {
282
- ...opts ,
283
- jobId,
284
- delay : delay < 0 ? 0 : delay ,
285
- timestamp : now ,
286
- prevMillis : nextMillis ,
287
- repeatJobKey : jobSchedulerId ,
288
- } ;
289
-
290
- mergedOpts . repeat = { ...opts . repeat , count : currentCount } ;
291
-
292
- const job = new this . Job < T , R , N > ( this , name , data , mergedOpts , jobId ) ;
293
- job . addJob ( client ) ;
294
-
295
- if ( producerId ) {
296
- const producerJobKey = this . toKey ( producerId ) ;
297
- client . hset ( producerJobKey , 'nrjid' , job . id ) ;
298
- }
299
-
300
- return job ;
301
- }
302
-
303
257
async removeJobScheduler ( jobSchedulerId : string ) : Promise < number > {
304
258
return this . scripts . removeJobScheduler ( jobSchedulerId ) ;
305
259
}
0 commit comments