diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2017-10-06 17:06:55 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2017-10-06 17:06:55 +0000 |
commit | fb70fadaca6d2ce30730e9a6c995ad8e4f0526e3 (patch) | |
tree | 846e43a446ab90c4320cee4d1c1379851ebb10ea /app/workers/wait_for_cluster_creation_worker.rb | |
parent | a68a39e34120e0cf67d95e143326d03f61288cdf (diff) | |
parent | 86cea3a544951b1d2fd9795c6ffb83e98cbd97cd (diff) | |
download | gitlab-ce-fb70fadaca6d2ce30730e9a6c995ad8e4f0526e3.tar.gz |
Merge branch 'feature/sm/35954-create-kubernetes-cluster-on-gke-from-k8s-service' into 'master'
Create Kubernetes cluster on GKE from k8s service
Closes #35954
See merge request gitlab-org/gitlab-ce!14470
Diffstat (limited to 'app/workers/wait_for_cluster_creation_worker.rb')
-rw-r--r-- | app/workers/wait_for_cluster_creation_worker.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/app/workers/wait_for_cluster_creation_worker.rb b/app/workers/wait_for_cluster_creation_worker.rb new file mode 100644 index 00000000000..5aa3bbdaa9d --- /dev/null +++ b/app/workers/wait_for_cluster_creation_worker.rb @@ -0,0 +1,27 @@ +class WaitForClusterCreationWorker + include Sidekiq::Worker + include ClusterQueue + + INITIAL_INTERVAL = 2.minutes + EAGER_INTERVAL = 10.seconds + TIMEOUT = 20.minutes + + def perform(cluster_id) + Gcp::Cluster.find_by_id(cluster_id).try do |cluster| + Ci::FetchGcpOperationService.new.execute(cluster) do |operation| + case operation.status + when 'RUNNING' + if TIMEOUT < Time.now.utc - operation.start_time.to_time.utc + return cluster.make_errored!("Cluster creation time exceeds timeout; #{TIMEOUT}") + end + + WaitForClusterCreationWorker.perform_in(EAGER_INTERVAL, cluster.id) + when 'DONE' + Ci::FinalizeClusterCreationService.new.execute(cluster) + else + return cluster.make_errored!("Unexpected operation status; #{operation.status} #{operation.status_message}") + end + end + end + end +end |