Class: Clusters::Applications::DeactivateIntegrationWorker

Inherits:
Object
  • Object
show all
Includes:
ApplicationWorker, ClusterQueue
Defined in:
app/workers/clusters/applications/deactivate_integration_worker.rb

Overview

rubocop:disable Scalability/IdempotentWorker

Constant Summary

Constants included from ApplicationWorker

ApplicationWorker::LOGGING_EXTRA_KEY, ApplicationWorker::SAFE_PUSH_BULK_LIMIT

Constants included from Gitlab::Loggable

Gitlab::Loggable::ANONYMOUS

Constants included from WorkerAttributes

WorkerAttributes::DEFAULT_DATA_CONSISTENCY, WorkerAttributes::DEFAULT_DEFER_DELAY, WorkerAttributes::NAMESPACE_WEIGHTS, WorkerAttributes::VALID_DATA_CONSISTENCIES, WorkerAttributes::VALID_RESOURCE_BOUNDARIES, WorkerAttributes::VALID_URGENCIES

Instance Method Summary collapse

Methods included from Gitlab::Loggable

#build_structured_payload

Methods included from Gitlab::SidekiqVersioning::Worker

#job_version

Methods included from WorkerContext

#with_context

Instance Method Details

#cluster_missing_error(integration_name) ⇒ Object



33
34
35
36
37
38
# File 'app/workers/clusters/applications/deactivate_integration_worker.rb', line 33

def cluster_missing_error(integration_name)
  ActiveRecord::RecordNotFound.new(
    "Can't deactivate #{integration_name} integrations, host cluster not found! " \
    "Some inconsistent records may be left in database."
  )
end

#perform(cluster_id, integration_name) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/workers/clusters/applications/deactivate_integration_worker.rb', line 15

def perform(cluster_id, integration_name)
  cluster = Clusters::Cluster.find_by_id(cluster_id)
  raise cluster_missing_error(integration_name) unless cluster

  integration_class = Integration.integration_name_to_model(integration_name)
  integration_association_name = ::Project.integration_association_name(integration_name).to_sym

  projects = cluster.all_projects
    .with_integration(integration_class)
    .include_integration(integration_association_name)

  projects.find_each do |project|
    # This use of public_send is safe because we constructed the
    # integration_association_name ourselves above.
    project.public_send(integration_association_name).update!(active: false) # rubocop:disable GitlabSecurity/PublicSend
  end
end