bullmq 5.62.0 → 5.62.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31,9 +31,7 @@
31
31
 
32
32
  Output:
33
33
  repeatableKey - OK
34
- ]]
35
-
36
- local rcall = redis.call
34
+ ]] local rcall = redis.call
37
35
  local repeatKey = KEYS[1]
38
36
  local delayedKey = KEYS[2]
39
37
  local waitKey = KEYS[3]
@@ -82,8 +80,8 @@ if every then
82
80
  nextMillis, newOffset = getJobSchedulerEveryNextMillis(prevMillis, every, now, offset, startDate)
83
81
  end
84
82
 
85
- local function removeJobFromScheduler(prefixKey, delayedKey, prioritizedKey, waitKey, pausedKey, jobId,
86
- metaKey, eventsKey)
83
+ local function removeJobFromScheduler(prefixKey, delayedKey, prioritizedKey, waitKey, pausedKey, jobId, metaKey,
84
+ eventsKey)
87
85
  if rcall("ZSCORE", delayedKey, jobId) then
88
86
  removeJob(jobId, true, prefixKey, true --[[remove debounce key]] )
89
87
  rcall("ZREM", delayedKey, jobId)
@@ -107,23 +105,25 @@ local function removeJobFromScheduler(prefixKey, delayedKey, prioritizedKey, wai
107
105
  return false
108
106
  end
109
107
 
110
- local hadPrevJob = false
111
- if prevMillis then
108
+ local removedPrevJob = false
109
+ if prevMillis then
112
110
  local currentJobId = "repeat:" .. jobSchedulerId .. ":" .. prevMillis
113
111
  local currentJobKey = schedulerKey .. ":" .. prevMillis
114
-
112
+
115
113
  -- In theory it should always exist the currentJobKey if there is a prevMillis unless something has
116
114
  -- gone really wrong.
117
115
  if rcall("EXISTS", currentJobKey) == 1 then
118
- hadPrevJob = removeJobFromScheduler(prefixKey, delayedKey, prioritizedKey, waitKey, pausedKey,
119
- currentJobId, metaKey, eventsKey)
116
+ removedPrevJob = removeJobFromScheduler(prefixKey, delayedKey, prioritizedKey, waitKey, pausedKey, currentJobId,
117
+ metaKey, eventsKey)
120
118
  end
121
119
  end
122
120
 
123
- if hadPrevJob then
121
+ if removedPrevJob then
124
122
  -- The jobs has been removed and we want to replace it, so lets use the same millis.
125
- nextMillis = prevMillis
126
- else
123
+ if every then
124
+ nextMillis = prevMillis
125
+ end
126
+ else
127
127
  -- Special case where no job was removed, and we need to add the next iteration.
128
128
  schedulerOpts['offset'] = newOffset
129
129
  end
@@ -132,14 +132,17 @@ end
132
132
  local jobId = "repeat:" .. jobSchedulerId .. ":" .. nextMillis
133
133
  local jobKey = prefixKey .. jobId
134
134
 
135
- -- If there's already a job with this ID, handle the collision
135
+ -- If there's already a job with this ID, in a state
136
+ -- that is not updatable (active, completed, failed) we must
137
+ -- handle the collision
138
+ local hasCollision = false
136
139
  if rcall("EXISTS", jobKey) == 1 then
137
140
  if every then
138
141
  -- For 'every' case: try next time slot to avoid collision
139
142
  local nextSlotMillis = nextMillis + every
140
143
  local nextSlotJobId = "repeat:" .. jobSchedulerId .. ":" .. nextSlotMillis
141
144
  local nextSlotJobKey = prefixKey .. nextSlotJobId
142
-
145
+
143
146
  if rcall("EXISTS", nextSlotJobKey) == 0 then
144
147
  -- Next slot is free, use it
145
148
  nextMillis = nextSlotMillis
@@ -149,8 +152,7 @@ if rcall("EXISTS", jobKey) == 1 then
149
152
  return -11 -- SchedulerJobSlotsBusy
150
153
  end
151
154
  else
152
- -- For 'pattern' case: return error code
153
- return -10 -- SchedulerJobIdCollision
155
+ hasCollision = true
154
156
  end
155
157
  end
156
158
 
@@ -162,15 +164,20 @@ if delay < 0 then
162
164
  end
163
165
 
164
166
  local nextJobKey = schedulerKey .. ":" .. nextMillis
165
- -- jobId already calculated above during collision check
166
167
 
167
- storeJobScheduler(jobSchedulerId, schedulerKey, repeatKey, nextMillis, schedulerOpts, templateData, templateOpts)
168
+ if not hasCollision or removedPrevJob then
169
+ -- jobId already calculated above during collision check
168
170
 
169
- rcall("INCR", KEYS[8])
171
+ storeJobScheduler(jobSchedulerId, schedulerKey, repeatKey, nextMillis, schedulerOpts, templateData, templateOpts)
170
172
 
171
- addJobFromScheduler(nextJobKey, jobId, jobOpts, waitKey, pausedKey,
172
- KEYS[11], metaKey, prioritizedKey, KEYS[10], delayedKey, KEYS[7], eventsKey,
173
- schedulerOpts['name'], maxEvents, now, templateData, jobSchedulerId, delay)
173
+ rcall("INCR", KEYS[8])
174
+
175
+ addJobFromScheduler(nextJobKey, jobId, jobOpts, waitKey, pausedKey, KEYS[11], metaKey, prioritizedKey, KEYS[10],
176
+ delayedKey, KEYS[7], eventsKey, schedulerOpts['name'], maxEvents, now, templateData, jobSchedulerId, delay)
177
+ elseif hasCollision then
178
+ -- For 'pattern' case: return error code
179
+ return -10 -- SchedulerJobIdCollision
180
+ end
174
181
 
175
182
  if ARGV[9] ~= "" then
176
183
  rcall("HSET", ARGV[9], "nrjid", jobId)
@@ -31,8 +31,7 @@ const content = `--[[
31
31
  ARGV[9] producer key
32
32
  Output:
33
33
  repeatableKey - OK
34
- ]]
35
- local rcall = redis.call
34
+ ]] local rcall = redis.call
36
35
  local repeatKey = KEYS[1]
37
36
  local delayedKey = KEYS[2]
38
37
  local waitKey = KEYS[3]
@@ -460,8 +459,8 @@ if every then
460
459
  local startDate = schedulerOpts['startDate']
461
460
  nextMillis, newOffset = getJobSchedulerEveryNextMillis(prevMillis, every, now, offset, startDate)
462
461
  end
463
- local function removeJobFromScheduler(prefixKey, delayedKey, prioritizedKey, waitKey, pausedKey, jobId,
464
- metaKey, eventsKey)
462
+ local function removeJobFromScheduler(prefixKey, delayedKey, prioritizedKey, waitKey, pausedKey, jobId, metaKey,
463
+ eventsKey)
465
464
  if rcall("ZSCORE", delayedKey, jobId) then
466
465
  removeJob(jobId, true, prefixKey, true --[[remove debounce key]] )
467
466
  rcall("ZREM", delayedKey, jobId)
@@ -482,28 +481,33 @@ local function removeJobFromScheduler(prefixKey, delayedKey, prioritizedKey, wai
482
481
  end
483
482
  return false
484
483
  end
485
- local hadPrevJob = false
486
- if prevMillis then
484
+ local removedPrevJob = false
485
+ if prevMillis then
487
486
  local currentJobId = "repeat:" .. jobSchedulerId .. ":" .. prevMillis
488
487
  local currentJobKey = schedulerKey .. ":" .. prevMillis
489
488
  -- In theory it should always exist the currentJobKey if there is a prevMillis unless something has
490
489
  -- gone really wrong.
491
490
  if rcall("EXISTS", currentJobKey) == 1 then
492
- hadPrevJob = removeJobFromScheduler(prefixKey, delayedKey, prioritizedKey, waitKey, pausedKey,
493
- currentJobId, metaKey, eventsKey)
491
+ removedPrevJob = removeJobFromScheduler(prefixKey, delayedKey, prioritizedKey, waitKey, pausedKey, currentJobId,
492
+ metaKey, eventsKey)
494
493
  end
495
494
  end
496
- if hadPrevJob then
495
+ if removedPrevJob then
497
496
  -- The jobs has been removed and we want to replace it, so lets use the same millis.
498
- nextMillis = prevMillis
499
- else
497
+ if every then
498
+ nextMillis = prevMillis
499
+ end
500
+ else
500
501
  -- Special case where no job was removed, and we need to add the next iteration.
501
502
  schedulerOpts['offset'] = newOffset
502
503
  end
503
504
  -- Check for job ID collision with existing jobs (in any state)
504
505
  local jobId = "repeat:" .. jobSchedulerId .. ":" .. nextMillis
505
506
  local jobKey = prefixKey .. jobId
506
- -- If there's already a job with this ID, handle the collision
507
+ -- If there's already a job with this ID, in a state
508
+ -- that is not updatable (active, completed, failed) we must
509
+ -- handle the collision
510
+ local hasCollision = false
507
511
  if rcall("EXISTS", jobKey) == 1 then
508
512
  if every then
509
513
  -- For 'every' case: try next time slot to avoid collision
@@ -519,8 +523,7 @@ if rcall("EXISTS", jobKey) == 1 then
519
523
  return -11 -- SchedulerJobSlotsBusy
520
524
  end
521
525
  else
522
- -- For 'pattern' case: return error code
523
- return -10 -- SchedulerJobIdCollision
526
+ hasCollision = true
524
527
  end
525
528
  end
526
529
  local delay = nextMillis - now
@@ -529,12 +532,16 @@ if delay < 0 then
529
532
  delay = 0
530
533
  end
531
534
  local nextJobKey = schedulerKey .. ":" .. nextMillis
532
- -- jobId already calculated above during collision check
533
- storeJobScheduler(jobSchedulerId, schedulerKey, repeatKey, nextMillis, schedulerOpts, templateData, templateOpts)
534
- rcall("INCR", KEYS[8])
535
- addJobFromScheduler(nextJobKey, jobId, jobOpts, waitKey, pausedKey,
536
- KEYS[11], metaKey, prioritizedKey, KEYS[10], delayedKey, KEYS[7], eventsKey,
537
- schedulerOpts['name'], maxEvents, now, templateData, jobSchedulerId, delay)
535
+ if not hasCollision or removedPrevJob then
536
+ -- jobId already calculated above during collision check
537
+ storeJobScheduler(jobSchedulerId, schedulerKey, repeatKey, nextMillis, schedulerOpts, templateData, templateOpts)
538
+ rcall("INCR", KEYS[8])
539
+ addJobFromScheduler(nextJobKey, jobId, jobOpts, waitKey, pausedKey, KEYS[11], metaKey, prioritizedKey, KEYS[10],
540
+ delayedKey, KEYS[7], eventsKey, schedulerOpts['name'], maxEvents, now, templateData, jobSchedulerId, delay)
541
+ elseif hasCollision then
542
+ -- For 'pattern' case: return error code
543
+ return -10 -- SchedulerJobIdCollision
544
+ end
538
545
  if ARGV[9] ~= "" then
539
546
  rcall("HSET", ARGV[9], "nrjid", jobId)
540
547
  end
@@ -1 +1 @@
1
- {"version":3,"file":"addJobScheduler-11.js","sourceRoot":"","sources":["../../../src/scripts/addJobScheduler-11.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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