getState-8.js 1.5 KB

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