@@ -93,19 +93,19 @@ export class JobScheduler extends QueueBase {
9393 }
9494
9595 let nextMillis : number ;
96- let newOffset = offset || 0 ;
96+ let newOffset = 0 ;
9797
9898 if ( every ) {
9999 const prevSlot = Math . floor ( startMillis / every ) * every ;
100100 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 ) {
102106 nextMillis = nextSlot ;
103107 } else {
104108 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 ;
109109 }
110110 } else if ( pattern ) {
111111 nextMillis = await this . repeatStrategy ( now , repeatOpts , jobName ) ;
@@ -246,7 +246,6 @@ export class JobScheduler extends QueueBase {
246246 mergedOpts . repeat = {
247247 ...opts . repeat ,
248248 count : currentCount ,
249- offset,
250249 endDate : opts . repeat ?. endDate
251250 ? new Date ( opts . repeat . endDate ) . getTime ( )
252251 : undefined ,
@@ -255,51 +254,6 @@ export class JobScheduler extends QueueBase {
255254 return mergedOpts ;
256255 }
257256
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-
303257 async removeJobScheduler ( jobSchedulerId : string ) : Promise < number > {
304258 return this . scripts . removeJobScheduler ( jobSchedulerId ) ;
305259 }
0 commit comments