removeJobFromAnyState.lua 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. --[[
  2. Function to remove from any state.
  3. returns:
  4. prev state
  5. ]]
  6. local function removeJobFromAnyState( prefix, jobId)
  7. -- We start with the ZSCORE checks, since they have O(1) complexity
  8. if rcall("ZSCORE", prefix .. "completed", jobId) then
  9. rcall("ZREM", prefix .. "completed", jobId)
  10. return "completed"
  11. elseif rcall("ZSCORE", prefix .. "waiting-children", jobId) then
  12. rcall("ZREM", prefix .. "waiting-children", jobId)
  13. return "waiting-children"
  14. elseif rcall("ZSCORE", prefix .. "delayed", jobId) then
  15. rcall("ZREM", prefix .. "delayed", jobId)
  16. return "delayed"
  17. elseif rcall("ZSCORE", prefix .. "failed", jobId) then
  18. rcall("ZREM", prefix .. "failed", jobId)
  19. return "failed"
  20. elseif rcall("ZSCORE", prefix .. "prioritized", jobId) then
  21. rcall("ZREM", prefix .. "prioritized", jobId)
  22. return "prioritized"
  23. -- We remove only 1 element from the list, since we assume they are not added multiple times
  24. elseif rcall("LREM", prefix .. "wait", 1, jobId) == 1 then
  25. return "wait"
  26. elseif rcall("LREM", prefix .. "paused", 1, jobId) == 1 then
  27. return "paused"
  28. elseif rcall("LREM", prefix .. "active", 1, jobId) == 1 then
  29. return "active"
  30. end
  31. return "unknown"
  32. end