summaryrefslogtreecommitdiff
path: root/app/services/admin/propagate_integration_service.rb
blob: 80e27c21d5b9750067d5beda4138e5a7ce412248 (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
29
30
31
32
# frozen_string_literal: true

module Admin
  class PropagateIntegrationService
    include PropagateService

    def propagate
      update_inherited_integrations

      create_integration_for_groups_without_integration if Feature.enabled?(:group_level_integrations)
      create_integration_for_projects_without_integration
    end

    private

    # rubocop: disable Cop/InBatches
    def update_inherited_integrations
      Service.by_type(integration.type).inherit_from_id(integration.id).in_batches(of: BATCH_SIZE) do |services|
        min_id, max_id = services.pick("MIN(services.id), MAX(services.id)")
        PropagateIntegrationInheritWorker.perform_async(integration.id, min_id, max_id)
      end
    end
    # rubocop: enable Cop/InBatches

    def create_integration_for_groups_without_integration
      Group.without_integration(integration).each_batch(of: BATCH_SIZE) do |groups|
        min_id, max_id = groups.pick("MIN(namespaces.id), MAX(namespaces.id)")
        PropagateIntegrationGroupWorker.perform_async(integration.id, min_id, max_id)
      end
    end
  end
end