fluke/devops-service/lib/helpers/job_waiter.rb

28 lines
636 B
Ruby
Raw Normal View History

module Devops
module Helpers
class JobWaiter
class TimeoutReached < StandardError; end
INTERVAL = 5
# timeout in seconds
def initialize(job_id, timeout=5000)
@job_id, @timeout = job_id, timeout
end
def wait
(@timeout / INTERVAL).times do
sleep(INTERVAL)
report = ::Devops::Db.connector.report(@job_id)
case report.status
when Worker::STATUS::COMPLETED
return 0
when Worker::STATUS::FAILED
return report.job_result_code
end
end
raise TimeoutReached
end
end
end
end