2020-05-20 14:08:00 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Admin
|
|
|
|
class PropagateIntegrationService
|
2020-09-08 11:08:41 -04:00
|
|
|
include PropagateService
|
2020-05-20 14:08:00 -04:00
|
|
|
|
|
|
|
def propagate
|
2020-08-27 11:10:21 -04:00
|
|
|
update_inherited_integrations
|
2020-09-15 11:10:08 -04:00
|
|
|
|
|
|
|
create_integration_for_groups_without_integration if Feature.enabled?(:group_level_integrations)
|
2020-05-20 14:08:00 -04:00
|
|
|
create_integration_for_projects_without_integration
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# rubocop: disable Cop/InBatches
|
2020-08-27 11:10:21 -04:00
|
|
|
def update_inherited_integrations
|
2020-09-29 11:10:08 -04:00
|
|
|
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)
|
2020-05-20 14:08:00 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
# rubocop: enable Cop/InBatches
|
|
|
|
|
2020-09-15 11:10:08 -04:00
|
|
|
def create_integration_for_groups_without_integration
|
2020-09-29 11:10:08 -04:00
|
|
|
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)
|
2020-09-15 11:10:08 -04:00
|
|
|
end
|
|
|
|
end
|
2020-05-20 14:08:00 -04:00
|
|
|
end
|
|
|
|
end
|