removeRepeatable-3.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const content = `--[[
  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. --[[
  21. Function to remove job keys.
  22. ]]
  23. local function removeJobKeys(jobKey)
  24. return rcall("DEL", jobKey, jobKey .. ':logs', jobKey .. ':dependencies',
  25. jobKey .. ':processed', jobKey .. ':failed', jobKey .. ':unsuccessful')
  26. end
  27. -- legacy removal TODO: remove in next breaking change
  28. if millis then
  29. -- Delete next programmed job.
  30. local repeatJobId = ARGV[1] .. millis
  31. if(rcall("ZREM", KEYS[2], repeatJobId) == 1) then
  32. removeJobKeys(ARGV[4] .. repeatJobId)
  33. rcall("XADD", KEYS[3], "*", "event", "removed", "jobId", repeatJobId, "prev", "delayed");
  34. end
  35. end
  36. if(rcall("ZREM", KEYS[1], ARGV[2]) == 1) then
  37. return 0
  38. end
  39. -- new removal
  40. millis = rcall("ZSCORE", KEYS[1], ARGV[3])
  41. if millis then
  42. -- Delete next programmed job.
  43. local repeatJobId = "repeat:" .. ARGV[3] .. ":" .. millis
  44. if(rcall("ZREM", KEYS[2], repeatJobId) == 1) then
  45. removeJobKeys(ARGV[4] .. repeatJobId)
  46. rcall("XADD", KEYS[3], "*", "event", "removed", "jobId", repeatJobId, "prev", "delayed")
  47. end
  48. end
  49. if(rcall("ZREM", KEYS[1], ARGV[3]) == 1) then
  50. rcall("DEL", KEYS[1] .. ":" .. ARGV[3])
  51. return 0
  52. end
  53. return 1
  54. `;
  55. export const removeRepeatable = {
  56. name: 'removeRepeatable',
  57. content,
  58. keys: 3,
  59. };
  60. //# sourceMappingURL=removeRepeatable-3.js.map