updateProgress-3.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.updateProgress = void 0;
  4. const content = `--[[
  5. Update job progress
  6. Input:
  7. KEYS[1] Job id key
  8. KEYS[2] event stream key
  9. KEYS[3] meta key
  10. ARGV[1] id
  11. ARGV[2] progress
  12. Output:
  13. 0 - OK
  14. -1 - Missing job.
  15. Event:
  16. progress(jobId, progress)
  17. ]]
  18. local rcall = redis.call
  19. -- Includes
  20. --[[
  21. Function to get max events value or set by default 10000.
  22. ]]
  23. local function getOrSetMaxEvents(metaKey)
  24. local maxEvents = rcall("HGET", metaKey, "opts.maxLenEvents")
  25. if not maxEvents then
  26. maxEvents = 10000
  27. rcall("HSET", metaKey, "opts.maxLenEvents", maxEvents)
  28. end
  29. return maxEvents
  30. end
  31. if rcall("EXISTS", KEYS[1]) == 1 then -- // Make sure job exists
  32. local maxEvents = getOrSetMaxEvents(KEYS[3])
  33. rcall("HSET", KEYS[1], "progress", ARGV[2])
  34. rcall("XADD", KEYS[2], "MAXLEN", "~", maxEvents, "*", "event", "progress",
  35. "jobId", ARGV[1], "data", ARGV[2]);
  36. return 0
  37. else
  38. return -1
  39. end
  40. `;
  41. exports.updateProgress = {
  42. name: 'updateProgress',
  43. content,
  44. keys: 3,
  45. };
  46. //# sourceMappingURL=updateProgress-3.js.map