updateProgress-3.js 1.0 KB

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