27 lines
609 B
Ruby
27 lines
609 B
Ruby
|
|
module Devops
|
||
|
|
module Helpers
|
||
|
|
class JobWaiter
|
||
|
|
class TimeoutReached < StandardError; end
|
||
|
|
|
||
|
|
INTERVAL = 5
|
||
|
|
|
||
|
|
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
|