bullmq 5.62.1 → 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.
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0hBf,CAAC;AACF,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,IAAI,EAAE,iBAAiB;IACvB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
1
+ {"version":3,"file":"addJobScheduler-11.js","sourceRoot":"","sources":["../../../src/scripts/addJobScheduler-11.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