diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2017-10-07 08:07:33 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2017-10-07 08:07:33 +0000 |
commit | 5ee20b637553dcb70590edfa30b81d972de37170 (patch) | |
tree | 7079e097120fc25438b411c6162a1ae81656c129 /app/workers | |
parent | c0cfc9ebd26583c444f2cce1a23f939bfa7d8969 (diff) | |
parent | d4f3963e98397a0aee4b7a65c76ae404300b41d1 (diff) | |
download | gitlab-ce-5ee20b637553dcb70590edfa30b81d972de37170.tar.gz |
Merge branch 'master' into '37970-ci-sections-tracking'
# Conflicts:
# db/schema.rb
Diffstat (limited to 'app/workers')
-rw-r--r-- | app/workers/cluster_provision_worker.rb | 10 | ||||
-rw-r--r-- | app/workers/concerns/cluster_queue.rb | 10 | ||||
-rw-r--r-- | app/workers/wait_for_cluster_creation_worker.rb | 27 |
3 files changed, 47 insertions, 0 deletions
diff --git a/app/workers/cluster_provision_worker.rb b/app/workers/cluster_provision_worker.rb new file mode 100644 index 00000000000..63300b58a25 --- /dev/null +++ b/app/workers/cluster_provision_worker.rb @@ -0,0 +1,10 @@ +class ClusterProvisionWorker + include Sidekiq::Worker + include ClusterQueue + + def perform(cluster_id) + Gcp::Cluster.find_by_id(cluster_id).try do |cluster| + Ci::ProvisionClusterService.new.execute(cluster) + end + end +end diff --git a/app/workers/concerns/cluster_queue.rb b/app/workers/concerns/cluster_queue.rb new file mode 100644 index 00000000000..a5074d13220 --- /dev/null +++ b/app/workers/concerns/cluster_queue.rb @@ -0,0 +1,10 @@ +## +# Concern for setting Sidekiq settings for the various Gcp clusters workers. +# +module ClusterQueue + extend ActiveSupport::Concern + + included do + sidekiq_options queue: :gcp_cluster + end +end 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 |