getCountsPerPriority-4.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.getCountsPerPriority = void 0;
  4. const content = `--[[
  5. Get counts per provided states
  6. Input:
  7. KEYS[1] wait key
  8. KEYS[2] paused key
  9. KEYS[3] meta key
  10. KEYS[4] prioritized key
  11. ARGV[1...] priorities
  12. ]]
  13. local rcall = redis.call
  14. local results = {}
  15. local waitKey = KEYS[1]
  16. local pausedKey = KEYS[2]
  17. local prioritizedKey = KEYS[4]
  18. -- Includes
  19. --[[
  20. Function to check for the meta.paused key to decide if we are paused or not
  21. (since an empty list and !EXISTS are not really the same).
  22. ]]
  23. local function isQueuePaused(queueMetaKey)
  24. return rcall("HEXISTS", queueMetaKey, "paused") == 1
  25. end
  26. for i = 1, #ARGV do
  27. local priority = tonumber(ARGV[i])
  28. if priority == 0 then
  29. if isQueuePaused(KEYS[3]) then
  30. results[#results+1] = rcall("LLEN", pausedKey)
  31. else
  32. results[#results+1] = rcall("LLEN", waitKey)
  33. end
  34. else
  35. results[#results+1] = rcall("ZCOUNT", prioritizedKey,
  36. priority * 0x100000000, (priority + 1) * 0x100000000 - 1)
  37. end
  38. end
  39. return results
  40. `;
  41. exports.getCountsPerPriority = {
  42. name: 'getCountsPerPriority',
  43. content,
  44. keys: 4,
  45. };
  46. //# sourceMappingURL=getCountsPerPriority-4.js.map