changePriority-7.lua 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. --[[
  2. Change job priority
  3. Input:
  4. KEYS[1] 'wait',
  5. KEYS[2] 'paused'
  6. KEYS[3] 'meta'
  7. KEYS[4] 'prioritized'
  8. KEYS[5] 'active'
  9. KEYS[6] 'pc' priority counter
  10. KEYS[7] 'marker'
  11. ARGV[1] priority value
  12. ARGV[2] prefix key
  13. ARGV[3] job id
  14. ARGV[4] lifo
  15. Output:
  16. 0 - OK
  17. -1 - Missing job
  18. ]]
  19. local jobId = ARGV[3]
  20. local jobKey = ARGV[2] .. jobId
  21. local priority = tonumber(ARGV[1])
  22. local rcall = redis.call
  23. -- Includes
  24. --- @include "includes/addJobInTargetList"
  25. --- @include "includes/addJobWithPriority"
  26. --- @include "includes/getTargetQueueList"
  27. --- @include "includes/pushBackJobWithPriority"
  28. local function reAddJobWithNewPriority( prioritizedKey, markerKey, targetKey,
  29. priorityCounter, lifo, priority, jobId, isPausedOrMaxed)
  30. if priority == 0 then
  31. local pushCmd = lifo and 'RPUSH' or 'LPUSH'
  32. addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
  33. else
  34. if lifo then
  35. pushBackJobWithPriority(prioritizedKey, priority, jobId)
  36. else
  37. addJobWithPriority(markerKey, prioritizedKey, priority, jobId,
  38. priorityCounter, isPausedOrMaxed)
  39. end
  40. end
  41. end
  42. if rcall("EXISTS", jobKey) == 1 then
  43. local metaKey = KEYS[3]
  44. local target, isPausedOrMaxed = getTargetQueueList(metaKey, KEYS[5], KEYS[1], KEYS[2])
  45. local prioritizedKey = KEYS[4]
  46. local priorityCounterKey = KEYS[6]
  47. local markerKey = KEYS[7]
  48. -- Re-add with the new priority
  49. if rcall("ZREM", prioritizedKey, jobId) > 0 then
  50. reAddJobWithNewPriority( prioritizedKey, markerKey, target,
  51. priorityCounterKey, ARGV[4] == '1', priority, jobId, isPausedOrMaxed)
  52. elseif rcall("LREM", target, -1, jobId) > 0 then
  53. reAddJobWithNewPriority( prioritizedKey, markerKey, target,
  54. priorityCounterKey, ARGV[4] == '1', priority, jobId, isPausedOrMaxed)
  55. end
  56. rcall("HSET", jobKey, "priority", priority)
  57. return 0
  58. else
  59. return -1
  60. end