Commit 483d5c9f authored by Luke Duncalfe's avatar Luke Duncalfe Committed by Andy Soiron
parent 0b83283a
# 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
module Admin
class PropagateIntegrationService
include PropagateService
module Integrations
class PropagateService
BATCH_SIZE = 10_000
def initialize(integration)
@integration = integration
end
def propagate
if integration.instance_level?
......@@ -16,8 +20,21 @@ module Admin
end
end
def self.propagate(integration)
new(integration).propagate
end
private
attr_reader :integration
def create_integration_for_projects_without_integration
propagate_integrations(
Project.without_integration(integration),
PropagateIntegrationProjectWorker
)
end
def update_inherited_integrations
propagate_integrations(
Integration.by_type(integration.type).inherit_from_id(integration.id),
......@@ -52,5 +69,12 @@ module Admin
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
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
idempotent!
def perform(integration_id)
Admin::PropagateIntegrationService.propagate(Integration.find(integration_id))
::Integrations::PropagateService.propagate(Integration.find(integration_id))
end
end
......@@ -16,7 +16,7 @@ class PropagateServiceTemplateWorker # rubocop:disable Scalability/IdempotentWor
def perform(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
private
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe Admin::PropagateIntegrationService do
RSpec.describe Integrations::PropagateService do
describe '.propagate' do
include JiraServiceHelper
......
......@@ -18,7 +18,7 @@ RSpec.describe PropagateIntegrationWorker do
end
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)
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