getRanges-1.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.getRanges = void 0;
  4. const content = `--[[
  5. Get job ids per provided states
  6. Input:
  7. KEYS[1] 'prefix'
  8. ARGV[1] start
  9. ARGV[2] end
  10. ARGV[3] asc
  11. ARGV[4...] types
  12. ]]
  13. local rcall = redis.call
  14. local prefix = KEYS[1]
  15. local rangeStart = tonumber(ARGV[1])
  16. local rangeEnd = tonumber(ARGV[2])
  17. local asc = ARGV[3]
  18. local results = {}
  19. local function getRangeInList(listKey, asc, rangeStart, rangeEnd, results)
  20. if asc == "1" then
  21. local modifiedRangeStart
  22. local modifiedRangeEnd
  23. if rangeStart == -1 then
  24. modifiedRangeStart = 0
  25. else
  26. modifiedRangeStart = -(rangeStart + 1)
  27. end
  28. if rangeEnd == -1 then
  29. modifiedRangeEnd = 0
  30. else
  31. modifiedRangeEnd = -(rangeEnd + 1)
  32. end
  33. results[#results+1] = rcall("LRANGE", listKey,
  34. modifiedRangeEnd,
  35. modifiedRangeStart)
  36. else
  37. results[#results+1] = rcall("LRANGE", listKey, rangeStart, rangeEnd)
  38. end
  39. end
  40. for i = 4, #ARGV do
  41. local stateKey = prefix .. ARGV[i]
  42. if ARGV[i] == "wait" or ARGV[i] == "paused" then
  43. -- Markers in waitlist DEPRECATED in v5: Remove in v6.
  44. local marker = rcall("LINDEX", stateKey, -1)
  45. if marker and string.sub(marker, 1, 2) == "0:" then
  46. local count = rcall("LLEN", stateKey)
  47. if count > 1 then
  48. rcall("RPOP", stateKey)
  49. getRangeInList(stateKey, asc, rangeStart, rangeEnd, results)
  50. else
  51. results[#results+1] = {}
  52. end
  53. else
  54. getRangeInList(stateKey, asc, rangeStart, rangeEnd, results)
  55. end
  56. elseif ARGV[i] == "active" then
  57. getRangeInList(stateKey, asc, rangeStart, rangeEnd, results)
  58. else
  59. if asc == "1" then
  60. results[#results+1] = rcall("ZRANGE", stateKey, rangeStart, rangeEnd)
  61. else
  62. results[#results+1] = rcall("ZREVRANGE", stateKey, rangeStart, rangeEnd)
  63. end
  64. end
  65. end
  66. return results
  67. `;
  68. exports.getRanges = {
  69. name: 'getRanges',
  70. content,
  71. keys: 1,
  72. };
  73. //# sourceMappingURL=getRanges-1.js.map