summaryrefslogtreecommitdiff
path: root/app/workers
diff options
context:
space:
mode:
authorMayra Cabrera <mcabrera@gitlab.com>2018-09-06 19:20:42 +0000
committerKamil TrzciƄski <ayufan@ayufan.eu>2018-09-06 19:20:42 +0000
commit177d847cf5c0ad9f282f599fbd5e9dafdc3b6289 (patch)
treecf94abe3e3ae6b79582d9aa87e1d595b3f0dbda2 /app/workers
parenta286e20d014e4092be7f03a2e1679f8f8434afa2 (diff)
downloadgitlab-ce-177d847cf5c0ad9f282f599fbd5e9dafdc3b6289.tar.gz
Automatically disable Auto DevOps for project upon first pipeline failure
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/all_queues.yml2
-rw-r--r--app/workers/auto_devops/disable_worker.rb35
-rw-r--r--app/workers/concerns/auto_devops_queue.rb9
3 files changed, 46 insertions, 0 deletions
diff --git a/app/workers/all_queues.yml b/app/workers/all_queues.yml
index f95df7ecf03..ae9dc8d4857 100644
--- a/app/workers/all_queues.yml
+++ b/app/workers/all_queues.yml
@@ -1,4 +1,6 @@
---
+- auto_devops:auto_devops_disable
+
- cronjob:admin_email
- cronjob:expire_build_artifacts
- cronjob:gitlab_usage_ping
diff --git a/app/workers/auto_devops/disable_worker.rb b/app/workers/auto_devops/disable_worker.rb
new file mode 100644
index 00000000000..73ddc591505
--- /dev/null
+++ b/app/workers/auto_devops/disable_worker.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+module AutoDevops
+ class DisableWorker
+ include ApplicationWorker
+ include AutoDevopsQueue
+
+ def perform(pipeline_id)
+ pipeline = Ci::Pipeline.find(pipeline_id)
+ project = pipeline.project
+
+ send_notification_email(pipeline, project) if disable_service(project).execute
+ end
+
+ private
+
+ def disable_service(project)
+ Projects::AutoDevops::DisableService.new(project)
+ end
+
+ def send_notification_email(pipeline, project)
+ recipients = email_receivers_for(pipeline, project)
+
+ return unless recipients.any?
+
+ NotificationService.new.autodevops_disabled(pipeline, recipients)
+ end
+
+ def email_receivers_for(pipeline, project)
+ recipients = [pipeline.user&.email]
+ recipients << project.owner.email unless project.group
+ recipients.uniq.compact
+ end
+ end
+end
diff --git a/app/workers/concerns/auto_devops_queue.rb b/app/workers/concerns/auto_devops_queue.rb
new file mode 100644
index 00000000000..aba928ccaab
--- /dev/null
+++ b/app/workers/concerns/auto_devops_queue.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+#
+module AutoDevopsQueue
+ extend ActiveSupport::Concern
+
+ included do
+ queue_namespace :auto_devops
+ end
+end