pause-7.lua 1003 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. --[[
  2. Pauses or resumes a queue globably.
  3. Input:
  4. KEYS[1] 'wait' or 'paused''
  5. KEYS[2] 'paused' or 'wait'
  6. KEYS[3] 'meta'
  7. KEYS[4] 'prioritized'
  8. KEYS[5] events stream key
  9. KEYS[6] 'delayed'
  10. KEYS|7] 'marker'
  11. ARGV[1] 'paused' or 'resumed'
  12. Event:
  13. publish paused or resumed event.
  14. ]]
  15. local rcall = redis.call
  16. -- Includes
  17. --- @include "includes/addDelayMarkerIfNeeded"
  18. local markerKey = KEYS[7]
  19. local hasJobs = rcall("EXISTS", KEYS[1]) == 1
  20. --TODO: check this logic to be reused when changing a delay
  21. if hasJobs then rcall("RENAME", KEYS[1], KEYS[2]) end
  22. if ARGV[1] == "paused" then
  23. rcall("HSET", KEYS[3], "paused", 1)
  24. rcall("DEL", markerKey)
  25. else
  26. rcall("HDEL", KEYS[3], "paused")
  27. if hasJobs or rcall("ZCARD", KEYS[4]) > 0 then
  28. -- Add marker if there are waiting or priority jobs
  29. rcall("ZADD", markerKey, 0, "0")
  30. else
  31. addDelayMarkerIfNeeded(markerKey, KEYS[6])
  32. end
  33. end
  34. rcall("XADD", KEYS[5], "*", "event", ARGV[1]);