2017-09-30 15:54:22 +00:00
|
|
|
class WaitForClusterCreationWorker
|
|
|
|
include Sidekiq::Worker
|
2017-10-03 17:33:37 +00:00
|
|
|
include ClusterQueue
|
2017-09-30 15:54:22 +00:00
|
|
|
|
|
|
|
INITIAL_INTERVAL = 2.minutes
|
|
|
|
EAGER_INTERVAL = 10.seconds
|
|
|
|
TIMEOUT = 20.minutes
|
|
|
|
|
|
|
|
def perform(cluster_id)
|
2017-10-05 19:33:29 +00:00
|
|
|
Gcp::Cluster.find_by_id(cluster_id).try do |cluster|
|
2017-10-03 14:44:06 +00:00
|
|
|
Ci::FetchGcpOperationService.new.execute(cluster) do |operation|
|
|
|
|
case operation.status
|
|
|
|
when 'RUNNING'
|
2017-10-06 09:23:53 +00:00
|
|
|
if TIMEOUT < Time.now.utc - operation.start_time.to_time.utc
|
2017-10-04 13:14:01 +00:00
|
|
|
return cluster.make_errored!("Cluster creation time exceeds timeout; #{TIMEOUT}")
|
2017-10-03 14:44:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
WaitForClusterCreationWorker.perform_in(EAGER_INTERVAL, cluster.id)
|
|
|
|
when 'DONE'
|
|
|
|
Ci::FinalizeClusterCreationService.new.execute(cluster)
|
|
|
|
else
|
2017-10-04 13:14:01 +00:00
|
|
|
return cluster.make_errored!("Unexpected operation status; #{operation.status} #{operation.status_message}")
|
2017-10-03 14:44:06 +00:00
|
|
|
end
|
2017-09-30 15:54:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|