removeJobScheduler-3.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.removeJobScheduler = void 0;
  4. const content = `--[[
  5. Removes a job scheduler and its next scheduled job.
  6. Input:
  7. KEYS[1] job schedulers key
  8. KEYS[2] delayed jobs key
  9. KEYS[3] events key
  10. ARGV[1] job scheduler id
  11. ARGV[2] prefix key
  12. Output:
  13. 0 - OK
  14. 1 - Missing repeat job
  15. Events:
  16. 'removed'
  17. ]]
  18. local rcall = redis.call
  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. local jobSchedulerId = ARGV[1]
  28. local prefix = ARGV[2]
  29. local millis = rcall("ZSCORE", KEYS[1], jobSchedulerId)
  30. if millis then
  31. -- Delete next programmed job.
  32. local delayedJobId = "repeat:" .. jobSchedulerId .. ":" .. millis
  33. if(rcall("ZREM", KEYS[2], delayedJobId) == 1) then
  34. removeJobKeys(prefix .. delayedJobId)
  35. rcall("XADD", KEYS[3], "*", "event", "removed", "jobId", delayedJobId, "prev", "delayed")
  36. end
  37. end
  38. if(rcall("ZREM", KEYS[1], jobSchedulerId) == 1) then
  39. rcall("DEL", KEYS[1] .. ":" .. jobSchedulerId)
  40. return 0
  41. end
  42. return 1
  43. `;
  44. exports.removeJobScheduler = {
  45. name: 'removeJobScheduler',
  46. content,
  47. keys: 3,
  48. };
  49. //# sourceMappingURL=removeJobScheduler-3.js.map