removeRepeatable-3.lua 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. --[[
  2. Removes a repeatable job
  3. Input:
  4. KEYS[1] repeat jobs key
  5. KEYS[2] delayed jobs key
  6. KEYS[3] events key
  7. ARGV[1] old repeat job id
  8. ARGV[2] options concat
  9. ARGV[3] repeat job key
  10. ARGV[4] prefix key
  11. Output:
  12. 0 - OK
  13. 1 - Missing repeat job
  14. Events:
  15. 'removed'
  16. ]]
  17. local rcall = redis.call
  18. local millis = rcall("ZSCORE", KEYS[1], ARGV[2])
  19. -- Includes
  20. --- @include "includes/removeJobKeys"
  21. -- legacy removal TODO: remove in next breaking change
  22. if millis then
  23. -- Delete next programmed job.
  24. local repeatJobId = ARGV[1] .. millis
  25. if(rcall("ZREM", KEYS[2], repeatJobId) == 1) then
  26. removeJobKeys(ARGV[4] .. repeatJobId)
  27. rcall("XADD", KEYS[3], "*", "event", "removed", "jobId", repeatJobId, "prev", "delayed");
  28. end
  29. end
  30. if(rcall("ZREM", KEYS[1], ARGV[2]) == 1) then
  31. return 0
  32. end
  33. -- new removal
  34. millis = rcall("ZSCORE", KEYS[1], ARGV[3])
  35. if millis then
  36. -- Delete next programmed job.
  37. local repeatJobId = "repeat:" .. ARGV[3] .. ":" .. millis
  38. if(rcall("ZREM", KEYS[2], repeatJobId) == 1) then
  39. removeJobKeys(ARGV[4] .. repeatJobId)
  40. rcall("XADD", KEYS[3], "*", "event", "removed", "jobId", repeatJobId, "prev", "delayed")
  41. end
  42. end
  43. if(rcall("ZREM", KEYS[1], ARGV[3]) == 1) then
  44. rcall("DEL", KEYS[1] .. ":" .. ARGV[3])
  45. return 0
  46. end
  47. return 1