Commit d860ad98 authored by Andy Soiron's avatar Andy Soiron

Merge branch '330670-namespace-propagate-integrations-services' into 'master'

Namespace propagate integrations services

See merge request gitlab-org/gitlab!73437
parents 9ca3de45 483d5c9f
# frozen_string_literal: true
module Admin
class PropagateServiceTemplate
include PropagateService
def propagate
# TODO: Remove this as part of https://gitlab.com/gitlab-org/gitlab/-/issues/335178
end
end
end
# frozen_string_literal: true
module Admin
module PropagateService
extend ActiveSupport::Concern
BATCH_SIZE = 10_000
class_methods do
def propagate(integration)
new(integration).propagate
end
end
def initialize(integration)
@integration = integration
end
private
attr_reader :integration
def create_integration_for_projects_without_integration
propagate_integrations(
Project.without_integration(integration),
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
# frozen_string_literal: true # frozen_string_literal: true
module Admin module Integrations
class PropagateIntegrationService class PropagateService
include PropagateService BATCH_SIZE = 10_000
def initialize(integration)
@integration = integration
end
def propagate def propagate
if integration.instance_level? if integration.instance_level?
...@@ -16,8 +20,21 @@ module Admin ...@@ -16,8 +20,21 @@ module Admin
end end
end end
def self.propagate(integration)
new(integration).propagate
end
private private
attr_reader :integration
def create_integration_for_projects_without_integration
propagate_integrations(
Project.without_integration(integration),
PropagateIntegrationProjectWorker
)
end
def update_inherited_integrations def update_inherited_integrations
propagate_integrations( propagate_integrations(
Integration.by_type(integration.type).inherit_from_id(integration.id), Integration.by_type(integration.type).inherit_from_id(integration.id),
...@@ -52,5 +69,12 @@ module Admin ...@@ -52,5 +69,12 @@ module Admin
PropagateIntegrationProjectWorker PropagateIntegrationProjectWorker
) )
end 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
# frozen_string_literal: true
module Integrations
# TODO: Remove this as part of https://gitlab.com/gitlab-org/gitlab/-/issues/335178
class PropagateTemplateService
def self.propagate(_integration)
# no-op
end
end
end
...@@ -12,6 +12,6 @@ class PropagateIntegrationWorker ...@@ -12,6 +12,6 @@ class PropagateIntegrationWorker
idempotent! idempotent!
def perform(integration_id) def perform(integration_id)
Admin::PropagateIntegrationService.propagate(Integration.find(integration_id)) ::Integrations::PropagateService.propagate(Integration.find(integration_id))
end end
end end
...@@ -16,7 +16,7 @@ class PropagateServiceTemplateWorker # rubocop:disable Scalability/IdempotentWor ...@@ -16,7 +16,7 @@ class PropagateServiceTemplateWorker # rubocop:disable Scalability/IdempotentWor
def perform(template_id) def perform(template_id)
return unless try_obtain_lease_for(template_id) return unless try_obtain_lease_for(template_id)
Admin::PropagateServiceTemplate.propagate(Integration.find_by_id(template_id)) ::Integrations::PropagateTemplateService.propagate(Integration.find_by_id(template_id))
end end
private private
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Admin::PropagateIntegrationService do RSpec.describe Integrations::PropagateService do
describe '.propagate' do describe '.propagate' do
include JiraServiceHelper include JiraServiceHelper
......
...@@ -18,7 +18,7 @@ RSpec.describe PropagateIntegrationWorker do ...@@ -18,7 +18,7 @@ RSpec.describe PropagateIntegrationWorker do
end end
it 'calls the propagate service with the integration' do it 'calls the propagate service with the integration' do
expect(Admin::PropagateIntegrationService).to receive(:propagate).with(integration) expect(Integrations::PropagateService).to receive(:propagate).with(integration)
subject.perform(integration.id) subject.perform(integration.id)
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