removeJobScheduler-3.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const content = `--[[
  2. Removes a job scheduler and its next scheduled job.
  3. Input:
  4. KEYS[1] job schedulers key
  5. KEYS[2] delayed jobs key
  6. KEYS[3] events key
  7. ARGV[1] job scheduler id
  8. ARGV[2] prefix key
  9. Output:
  10. 0 - OK
  11. 1 - Missing repeat job
  12. Events:
  13. 'removed'
  14. ]]
  15. local rcall = redis.call
  16. -- Includes
  17. --[[
  18. Function to remove job keys.
  19. ]]
  20. local function removeJobKeys(jobKey)
  21. return rcall("DEL", jobKey, jobKey .. ':logs', jobKey .. ':dependencies',
  22. jobKey .. ':processed', jobKey .. ':failed', jobKey .. ':unsuccessful')
  23. end
  24. local jobSchedulerId = ARGV[1]
  25. local prefix = ARGV[2]
  26. local millis = rcall("ZSCORE", KEYS[1], jobSchedulerId)
  27. if millis then
  28. -- Delete next programmed job.
  29. local delayedJobId = "repeat:" .. jobSchedulerId .. ":" .. millis
  30. if(rcall("ZREM", KEYS[2], delayedJobId) == 1) then
  31. removeJobKeys(prefix .. delayedJobId)
  32. rcall("XADD", KEYS[3], "*", "event", "removed", "jobId", delayedJobId, "prev", "delayed")
  33. end
  34. end
  35. if(rcall("ZREM", KEYS[1], jobSchedulerId) == 1) then
  36. rcall("DEL", KEYS[1] .. ":" .. jobSchedulerId)
  37. return 0
  38. end
  39. return 1
  40. `;
  41. export const removeJobScheduler = {
  42. name: 'removeJobScheduler',
  43. content,
  44. keys: 3,
  45. };
  46. //# sourceMappingURL=removeJobScheduler-3.js.map