summaryrefslogtreecommitdiff
path: root/app/workers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-24 09:09:25 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-24 09:09:25 +0000
commit6f7881ee9dcec34141a8f34fc814b56b366d2b48 (patch)
tree25f72a06874b32b1049b79a9d7f4f1b7bca43b9b /app/workers
parent8c8bf44fa64f98114f7439f751c92d59a44b3218 (diff)
downloadgitlab-ce-6f7881ee9dcec34141a8f34fc814b56b366d2b48.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/all_queues.yml14
-rw-r--r--app/workers/cluster_update_app_worker.rb50
-rw-r--r--app/workers/cluster_wait_for_app_update_worker.rb16
3 files changed, 80 insertions, 0 deletions
diff --git a/app/workers/all_queues.yml b/app/workers/all_queues.yml
index f4d8483db84..cae4bb73e04 100644
--- a/app/workers/all_queues.yml
+++ b/app/workers/all_queues.yml
@@ -325,6 +325,13 @@
:resource_boundary: :unknown
:weight: 1
:idempotent:
+- :name: gcp_cluster:cluster_update_app
+ :feature_category: :kubernetes_management
+ :has_external_dependencies:
+ :urgency: :low
+ :resource_boundary: :unknown
+ :weight: 1
+ :idempotent:
- :name: gcp_cluster:cluster_upgrade_app
:feature_category: :kubernetes_management
:has_external_dependencies: true
@@ -339,6 +346,13 @@
:resource_boundary: :cpu
:weight: 1
:idempotent:
+- :name: gcp_cluster:cluster_wait_for_app_update
+ :feature_category: :kubernetes_management
+ :has_external_dependencies:
+ :urgency: :low
+ :resource_boundary: :unknown
+ :weight: 1
+ :idempotent:
- :name: gcp_cluster:cluster_wait_for_ingress_ip_address
:feature_category: :kubernetes_management
:has_external_dependencies: true
diff --git a/app/workers/cluster_update_app_worker.rb b/app/workers/cluster_update_app_worker.rb
new file mode 100644
index 00000000000..7ceeb167b33
--- /dev/null
+++ b/app/workers/cluster_update_app_worker.rb
@@ -0,0 +1,50 @@
+# frozen_string_literal: true
+
+class ClusterUpdateAppWorker # rubocop:disable Scalability/IdempotentWorker
+ UpdateAlreadyInProgressError = Class.new(StandardError)
+
+ include ApplicationWorker
+ include ClusterQueue
+ include ClusterApplications
+ include ExclusiveLeaseGuard
+
+ sidekiq_options retry: 3, dead: false
+
+ LEASE_TIMEOUT = 10.minutes.to_i
+
+ def perform(app_name, app_id, project_id, scheduled_time)
+ @app_id = app_id
+
+ try_obtain_lease do
+ execute(app_name, app_id, project_id, scheduled_time)
+ end
+ end
+
+ private
+
+ # rubocop: disable CodeReuse/ActiveRecord
+ def execute(app_name, app_id, project_id, scheduled_time)
+ project = Project.find_by(id: project_id)
+ return unless project
+
+ find_application(app_name, app_id) do |app|
+ update_prometheus(app, scheduled_time, project)
+ end
+ end
+ # rubocop: enable CodeReuse/ActiveRecord
+
+ def update_prometheus(app, scheduled_time, project)
+ return if app.updated_since?(scheduled_time)
+ return if app.update_in_progress?
+
+ Clusters::Applications::PrometheusUpdateService.new(app, project).execute
+ end
+
+ def lease_key
+ @lease_key ||= "#{self.class.name.underscore}-#{@app_id}"
+ end
+
+ def lease_timeout
+ LEASE_TIMEOUT
+ end
+end
diff --git a/app/workers/cluster_wait_for_app_update_worker.rb b/app/workers/cluster_wait_for_app_update_worker.rb
new file mode 100644
index 00000000000..9f1d83c2c7b
--- /dev/null
+++ b/app/workers/cluster_wait_for_app_update_worker.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class ClusterWaitForAppUpdateWorker # rubocop:disable Scalability/IdempotentWorker
+ include ApplicationWorker
+ include ClusterQueue
+ include ClusterApplications
+
+ INTERVAL = 10.seconds
+ TIMEOUT = 20.minutes
+
+ def perform(app_name, app_id)
+ find_application(app_name, app_id) do |app|
+ ::Clusters::Applications::CheckUpgradeProgressService.new(app).execute
+ end
+ end
+end