2018-09-06 15:20:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module AutoDevops
|
2020-02-19 13:09:10 -05:00
|
|
|
class DisableWorker # rubocop:disable Scalability/IdempotentWorker
|
2018-09-06 15:20:42 -04:00
|
|
|
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
|