removeRepeatable-3.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.removeRepeatable = void 0;
  4. const content = `--[[
  5. Removes a repeatable job
  6. Input:
  7. KEYS[1] repeat jobs key
  8. KEYS[2] delayed jobs key
  9. KEYS[3] events key
  10. ARGV[1] old repeat job id
  11. ARGV[2] options concat
  12. ARGV[3] repeat job key
  13. ARGV[4] prefix key
  14. Output:
  15. 0 - OK
  16. 1 - Missing repeat job
  17. Events:
  18. 'removed'
  19. ]]
  20. local rcall = redis.call
  21. local millis = rcall("ZSCORE", KEYS[1], ARGV[2])
  22. -- Includes
  23. --[[
  24. Function to remove job keys.
  25. ]]
  26. local function removeJobKeys(jobKey)
  27. return rcall("DEL", jobKey, jobKey .. ':logs', jobKey .. ':dependencies',
  28. jobKey .. ':processed', jobKey .. ':failed', jobKey .. ':unsuccessful')
  29. end
  30. -- legacy removal TODO: remove in next breaking change
  31. if millis then
  32. -- Delete next programmed job.
  33. local repeatJobId = ARGV[1] .. millis
  34. if(rcall("ZREM", KEYS[2], repeatJobId) == 1) then
  35. removeJobKeys(ARGV[4] .. repeatJobId)
  36. rcall("XADD", KEYS[3], "*", "event", "removed", "jobId", repeatJobId, "prev", "delayed");
  37. end
  38. end
  39. if(rcall("ZREM", KEYS[1], ARGV[2]) == 1) then
  40. return 0
  41. end
  42. -- new removal
  43. millis = rcall("ZSCORE", KEYS[1], ARGV[3])
  44. if millis then
  45. -- Delete next programmed job.
  46. local repeatJobId = "repeat:" .. ARGV[3] .. ":" .. millis
  47. if(rcall("ZREM", KEYS[2], repeatJobId) == 1) then
  48. removeJobKeys(ARGV[4] .. repeatJobId)
  49. rcall("XADD", KEYS[3], "*", "event", "removed", "jobId", repeatJobId, "prev", "delayed")
  50. end
  51. end
  52. if(rcall("ZREM", KEYS[1], ARGV[3]) == 1) then
  53. rcall("DEL", KEYS[1] .. ":" .. ARGV[3])
  54. return 0
  55. end
  56. return 1
  57. `;
  58. exports.removeRepeatable = {
  59. name: 'removeRepeatable',
  60. content,
  61. keys: 3,
  62. };
  63. //# sourceMappingURL=removeRepeatable-3.js.map