2019-12-10 07:53:40 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Clusters
|
|
|
|
module Applications
|
2020-02-19 18:09:10 +00:00
|
|
|
class DeactivateServiceWorker # rubocop:disable Scalability/IdempotentWorker
|
2019-12-10 07:53:40 +00:00
|
|
|
include ApplicationWorker
|
|
|
|
include ClusterQueue
|
|
|
|
|
2020-06-12 12:08:56 +00:00
|
|
|
loggable_arguments 1
|
|
|
|
|
2019-12-10 07:53:40 +00:00
|
|
|
def perform(cluster_id, service_name)
|
|
|
|
cluster = Clusters::Cluster.find_by_id(cluster_id)
|
|
|
|
raise cluster_missing_error(service_name) unless cluster
|
|
|
|
|
|
|
|
service = "#{service_name}_service".to_sym
|
|
|
|
cluster.all_projects.with_service(service).find_each do |project|
|
|
|
|
project.public_send(service).update!(active: false) # rubocop:disable GitlabSecurity/PublicSend
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def cluster_missing_error(service)
|
|
|
|
ActiveRecord::RecordNotFound.new("Can't deactivate #{service} services, host cluster not found! Some inconsistent records may be left in database.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|