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)
@@ -28,8 +28,7 @@ const content = `--[[
28
28
  ARGV[9] producer key
29
29
  Output:
30
30
  repeatableKey - OK
31
- ]]
32
- local rcall = redis.call
31
+ ]] local rcall = redis.call
33
32
  local repeatKey = KEYS[1]
34
33
  local delayedKey = KEYS[2]
35
34
  local waitKey = KEYS[3]
@@ -457,8 +456,8 @@ if every then
457
456
  local startDate = schedulerOpts['startDate']
458
457
  nextMillis, newOffset = getJobSchedulerEveryNextMillis(prevMillis, every, now, offset, startDate)
459
458
  end
460
- local function removeJobFromScheduler(prefixKey, delayedKey, prioritizedKey, waitKey, pausedKey, jobId,
461
- metaKey, eventsKey)
459
+ local function removeJobFromScheduler(prefixKey, delayedKey, prioritizedKey, waitKey, pausedKey, jobId, metaKey,
460
+ eventsKey)
462
461
  if rcall("ZSCORE", delayedKey, jobId) then
463
462
  removeJob(jobId, true, prefixKey, true --[[remove debounce key]] )
464
463
  rcall("ZREM", delayedKey, jobId)
@@ -479,28 +478,33 @@ local function removeJobFromScheduler(prefixKey, delayedKey, prioritizedKey, wai
479
478
  end
480
479
  return false
481
480
  end
482
- local hadPrevJob = false
483
- if prevMillis then
481
+ local removedPrevJob = false
482
+ if prevMillis then
484
483
  local currentJobId = "repeat:" .. jobSchedulerId .. ":" .. prevMillis
485
484
  local currentJobKey = schedulerKey .. ":" .. prevMillis
486
485
  -- In theory it should always exist the currentJobKey if there is a prevMillis unless something has
487
486
  -- gone really wrong.
488
487
  if rcall("EXISTS", currentJobKey) == 1 then
489
- hadPrevJob = removeJobFromScheduler(prefixKey, delayedKey, prioritizedKey, waitKey, pausedKey,
490
- currentJobId, metaKey, eventsKey)
488
+ removedPrevJob = removeJobFromScheduler(prefixKey, delayedKey, prioritizedKey, waitKey, pausedKey, currentJobId,
489
+ metaKey, eventsKey)
491
490
  end
492
491
  end
493
- if hadPrevJob then
492
+ if removedPrevJob then
494
493
  -- The jobs has been removed and we want to replace it, so lets use the same millis.
495
- nextMillis = prevMillis
496
- else
494
+ if every then
495
+ nextMillis = prevMillis
496
+ end
497
+ else
497
498
  -- Special case where no job was removed, and we need to add the next iteration.
498
499
  schedulerOpts['offset'] = newOffset
499
500
  end
500
501
  -- Check for job ID collision with existing jobs (in any state)
501
502
  local jobId = "repeat:" .. jobSchedulerId .. ":" .. nextMillis
502
503
  local jobKey = prefixKey .. jobId
503
- -- If there's already a job with this ID, handle the collision
504
+ -- If there's already a job with this ID, in a state
505
+ -- that is not updatable (active, completed, failed) we must
506
+ -- handle the collision
507
+ local hasCollision = false
504
508
  if rcall("EXISTS", jobKey) == 1 then
505
509
  if every then
506
510
  -- For 'every' case: try next time slot to avoid collision
@@ -516,8 +520,7 @@ if rcall("EXISTS", jobKey) == 1 then
516
520
  return -11 -- SchedulerJobSlotsBusy
517
521
  end
518
522
  else
519
- -- For 'pattern' case: return error code
520
- return -10 -- SchedulerJobIdCollision
523
+ hasCollision = true
521
524
  end
522
525
  end
523
526
  local delay = nextMillis - now
@@ -526,12 +529,16 @@ if delay < 0 then
526
529
  delay = 0
527
530
  end
528
531
  local nextJobKey = schedulerKey .. ":" .. nextMillis
529
- -- jobId already calculated above during collision check
530
- storeJobScheduler(jobSchedulerId, schedulerKey, repeatKey, nextMillis, schedulerOpts, templateData, templateOpts)
531
- rcall("INCR", KEYS[8])
532
- addJobFromScheduler(nextJobKey, jobId, jobOpts, waitKey, pausedKey,
533
- KEYS[11], metaKey, prioritizedKey, KEYS[10], delayedKey, KEYS[7], eventsKey,
534
- schedulerOpts['name'], maxEvents, now, templateData, jobSchedulerId, delay)
532
+ if not hasCollision or removedPrevJob then
533
+ -- jobId already calculated above during collision check
534
+ storeJobScheduler(jobSchedulerId, schedulerKey, repeatKey, nextMillis, schedulerOpts, templateData, templateOpts)
535
+ rcall("INCR", KEYS[8])
536
+ addJobFromScheduler(nextJobKey, jobId, jobOpts, waitKey, pausedKey, KEYS[11], metaKey, prioritizedKey, KEYS[10],
537
+ delayedKey, KEYS[7], eventsKey, schedulerOpts['name'], maxEvents, now, templateData, jobSchedulerId, delay)
538
+ elseif hasCollision then
539
+ -- For 'pattern' case: return error code
540
+ return -10 -- SchedulerJobIdCollision
541
+ end
535
542
  if ARGV[9] ~= "" then
536
543
  rcall("HSET", ARGV[9], "nrjid", jobId)
537
544
  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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