23 lines
		
	
	
		
			488 B
		
	
	
	
		
			Ruby
		
	
	
	
	
	
		
		
			
		
	
	
			23 lines
		
	
	
		
			488 B
		
	
	
	
		
			Ruby
		
	
	
	
	
	
|   | 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 |