debian-mirror-gitlab/app/services/admin/propagate_integration_service.rb

52 lines
2 KiB
Ruby
Raw Normal View History

2020-06-23 00:09:42 +05:30
# frozen_string_literal: true
module Admin
class PropagateIntegrationService
2020-11-24 15:15:51 +05:30
include PropagateService
2020-06-23 00:09:42 +05:30
def propagate
2020-11-24 15:15:51 +05:30
update_inherited_integrations
2020-06-23 00:09:42 +05:30
2021-01-03 14:25:43 +05:30
if integration.instance?
create_integration_for_groups_without_integration if Feature.enabled?(:group_level_integrations)
create_integration_for_projects_without_integration
else
create_integration_for_groups_without_integration_belonging_to_group
create_integration_for_projects_without_integration_belonging_to_group
end
2020-06-23 00:09:42 +05:30
end
private
# rubocop: disable Cop/InBatches
2020-11-24 15:15:51 +05:30
def update_inherited_integrations
2021-01-03 14:25:43 +05:30
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-06-23 00:09:42 +05:30
end
end
# rubocop: enable Cop/InBatches
2020-11-24 15:15:51 +05:30
def create_integration_for_groups_without_integration
2021-01-03 14:25:43 +05:30
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-06-23 00:09:42 +05:30
end
end
2021-01-03 14:25:43 +05:30
def create_integration_for_groups_without_integration_belonging_to_group
integration.group.descendants.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
2020-06-23 00:09:42 +05:30
end
2021-01-03 14:25:43 +05:30
def create_integration_for_projects_without_integration_belonging_to_group
Project.without_integration(integration).in_namespace(integration.group.self_and_descendants).each_batch(of: BATCH_SIZE) do |projects|
min_id, max_id = projects.pick("MIN(projects.id), MAX(projects.id)")
PropagateIntegrationProjectWorker.perform_async(integration.id, min_id, max_id)
end
2020-06-23 00:09:42 +05:30
end
end
end