summaryrefslogtreecommitdiff
path: root/app/workers/clusters/applications/deactivate_service_worker.rb
blob: 935b455a4fc0d1ec565caafeb95a44825de31f34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

module Clusters
  module Applications
    class DeactivateServiceWorker # rubocop:disable Scalability/IdempotentWorker
      include ApplicationWorker

      sidekiq_options retry: 3
      include ClusterQueue

      loggable_arguments 1

      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