Commit e8f578d0 authored by Arturo Herrero's avatar Arturo Herrero

Extract duplicated logic for propagate integrations

parent 4e6e79ec
...@@ -19,38 +19,38 @@ module Admin ...@@ -19,38 +19,38 @@ module Admin
private private
def update_inherited_integrations def update_inherited_integrations
Service.by_type(integration.type).inherit_from_id(integration.id).each_batch(of: BATCH_SIZE) do |services| propagate_integrations(
min_id, max_id = services.pick("MIN(services.id), MAX(services.id)") Service.by_type(integration.type).inherit_from_id(integration.id),
PropagateIntegrationInheritWorker.perform_async(integration.id, min_id, max_id) PropagateIntegrationInheritWorker
end )
end end
def update_inherited_descendant_integrations def update_inherited_descendant_integrations
Service.inherited_descendants_from_self_or_ancestors_from(integration).each_batch(of: BATCH_SIZE) do |services| propagate_integrations(
min_id, max_id = services.pick("MIN(services.id), MAX(services.id)") Service.inherited_descendants_from_self_or_ancestors_from(integration),
PropagateIntegrationInheritDescendantWorker.perform_async(integration.id, min_id, max_id) PropagateIntegrationInheritDescendantWorker
end )
end end
def create_integration_for_groups_without_integration def create_integration_for_groups_without_integration
Group.without_integration(integration).each_batch(of: BATCH_SIZE) do |groups| propagate_integrations(
min_id, max_id = groups.pick("MIN(namespaces.id), MAX(namespaces.id)") Group.without_integration(integration),
PropagateIntegrationGroupWorker.perform_async(integration.id, min_id, max_id) PropagateIntegrationGroupWorker
end )
end end
def create_integration_for_groups_without_integration_belonging_to_group def create_integration_for_groups_without_integration_belonging_to_group
integration.group.descendants.without_integration(integration).each_batch(of: BATCH_SIZE) do |groups| propagate_integrations(
min_id, max_id = groups.pick("MIN(namespaces.id), MAX(namespaces.id)") integration.group.descendants.without_integration(integration),
PropagateIntegrationGroupWorker.perform_async(integration.id, min_id, max_id) PropagateIntegrationGroupWorker
end )
end end
def create_integration_for_projects_without_integration_belonging_to_group 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| propagate_integrations(
min_id, max_id = projects.pick("MIN(projects.id), MAX(projects.id)") Project.without_integration(integration).in_namespace(integration.group.self_and_descendants),
PropagateIntegrationProjectWorker.perform_async(integration.id, min_id, max_id) PropagateIntegrationProjectWorker
end )
end end
end end
end end
...@@ -21,9 +21,16 @@ module Admin ...@@ -21,9 +21,16 @@ module Admin
attr_reader :integration attr_reader :integration
def create_integration_for_projects_without_integration def create_integration_for_projects_without_integration
Project.without_integration(integration).each_batch(of: BATCH_SIZE) do |projects| propagate_integrations(
min_id, max_id = projects.pick("MIN(projects.id), MAX(projects.id)") Project.without_integration(integration),
PropagateIntegrationProjectWorker.perform_async(integration.id, min_id, max_id) PropagateIntegrationProjectWorker
)
end
def propagate_integrations(relation, worker_class)
relation.each_batch(of: BATCH_SIZE) do |records|
min_id, max_id = records.pick("MIN(#{relation.table_name}.id), MAX(#{relation.table_name}.id)")
worker_class.perform_async(integration.id, min_id, max_id)
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment