getState-8.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.getState = void 0;
  4. const content = `--[[
  5. Get a job state
  6. Input:
  7. KEYS[1] 'completed' key,
  8. KEYS[2] 'failed' key
  9. KEYS[3] 'delayed' key
  10. KEYS[4] 'active' key
  11. KEYS[5] 'wait' key
  12. KEYS[6] 'paused' key
  13. KEYS[7] 'waiting-children' key
  14. KEYS[8] 'prioritized' key
  15. ARGV[1] job id
  16. Output:
  17. 'completed'
  18. 'failed'
  19. 'delayed'
  20. 'active'
  21. 'prioritized'
  22. 'waiting'
  23. 'waiting-children'
  24. 'unknown'
  25. ]]
  26. local rcall = redis.call
  27. if rcall("ZSCORE", KEYS[1], ARGV[1]) then
  28. return "completed"
  29. end
  30. if rcall("ZSCORE", KEYS[2], ARGV[1]) then
  31. return "failed"
  32. end
  33. if rcall("ZSCORE", KEYS[3], ARGV[1]) then
  34. return "delayed"
  35. end
  36. if rcall("ZSCORE", KEYS[8], ARGV[1]) then
  37. return "prioritized"
  38. end
  39. -- Includes
  40. --[[
  41. Functions to check if a item belongs to a list.
  42. ]]
  43. local function checkItemInList(list, item)
  44. for _, v in pairs(list) do
  45. if v == item then
  46. return 1
  47. end
  48. end
  49. return nil
  50. end
  51. local active_items = rcall("LRANGE", KEYS[4] , 0, -1)
  52. if checkItemInList(active_items, ARGV[1]) ~= nil then
  53. return "active"
  54. end
  55. local wait_items = rcall("LRANGE", KEYS[5] , 0, -1)
  56. if checkItemInList(wait_items, ARGV[1]) ~= nil then
  57. return "waiting"
  58. end
  59. local paused_items = rcall("LRANGE", KEYS[6] , 0, -1)
  60. if checkItemInList(paused_items, ARGV[1]) ~= nil then
  61. return "waiting"
  62. end
  63. if rcall("ZSCORE", KEYS[7], ARGV[1]) then
  64. return "waiting-children"
  65. end
  66. return "unknown"
  67. `;
  68. exports.getState = {
  69. name: 'getState',
  70. content,
  71. keys: 8,
  72. };
  73. //# sourceMappingURL=getState-8.js.map