isLocked.lua 957 B

12345678910111213141516171819202122232425262728293031323334
  1. --[[
  2. Function to recursively check if there are no locks
  3. on the jobs to be removed.
  4. returns:
  5. boolean
  6. ]]
  7. --- @include "destructureJobKey"
  8. local function isLocked( prefix, jobId, removeChildren)
  9. local jobKey = prefix .. jobId;
  10. -- Check if this job is locked
  11. local lockKey = jobKey .. ':lock'
  12. local lock = rcall("GET", lockKey)
  13. if not lock then
  14. if removeChildren == "1" then
  15. local dependencies = rcall("SMEMBERS", jobKey .. ":dependencies")
  16. if (#dependencies > 0) then
  17. for i, childJobKey in ipairs(dependencies) do
  18. -- We need to get the jobId for this job.
  19. local childJobId = getJobIdFromKey(childJobKey)
  20. local childJobPrefix = getJobKeyPrefix(childJobKey, childJobId)
  21. local result = isLocked( childJobPrefix, childJobId, removeChildren )
  22. if result then
  23. return true
  24. end
  25. end
  26. end
  27. end
  28. return false
  29. end
  30. return true
  31. end