Commit 8afc2b39 authored by Manoj M J's avatar Manoj M J

Make incremental rollout possible for "UserRefreshOverUserRangeWorker"

Make incremental rollout possible for "UserRefreshOverUserRangeWorker"
parent 130d2e1c
......@@ -24,7 +24,7 @@ module AuthorizedProjectUpdate
# `data_consistency :delayed` and not `idempotent!`
# See https://gitlab.com/gitlab-org/gitlab/-/issues/325291
deduplicate :until_executing, including_scheduled: true
data_consistency :delayed, feature_flag: :periodic_project_authorization_update_via_replica
data_consistency :delayed, feature_flag: :delayed_consistency_for_user_refresh_over_range_worker
def perform(start_user_id, end_user_id)
if Feature.enabled?(:periodic_project_authorization_update_via_replica)
......@@ -32,12 +32,17 @@ module AuthorizedProjectUpdate
enqueue_project_authorizations_refresh(user) if project_authorizations_needs_refresh?(user)
end
else
use_primary_database
AuthorizedProjectUpdate::RecalculateForUserRangeService.new(start_user_id, end_user_id).execute
end
end
private
def use_primary_database
# no-op in CE, overriden in EE
end
def project_authorizations_needs_refresh?(user)
AuthorizedProjectUpdate::FindRecordsDueForRefreshService.new(user).needs_refresh?
end
......@@ -49,3 +54,5 @@ module AuthorizedProjectUpdate
end
end
end
AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker.prepend_mod_with('AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker')
---
name: delayed_consistency_for_user_refresh_over_range_worker
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/61883
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/327092
milestone: '13.12'
type: development
group: group::access
default_enabled: false
# frozen_string_literal: true
module EE
module AuthorizedProjectUpdate
module UserRefreshOverUserRangeWorker # rubocop:disable Scalability/IdempotentWorker
extend ::Gitlab::Utils::Override
private
override :use_primary_database
def use_primary_database
if ::Gitlab::Database::LoadBalancing.enable?
::Gitlab::Database::LoadBalancing::Session.current.use_primary!
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker do
let_it_be(:project) { create(:project) }
let(:user) { project.namespace.owner }
let(:start_user_id) { user.id }
let(:end_user_id) { start_user_id }
let(:execute_worker) { subject.perform(start_user_id, end_user_id) }
describe '#perform' do
context 'when the feature flag `periodic_project_authorization_update_via_replica` is disabled' do
before do
stub_feature_flags(periodic_project_authorization_update_via_replica: false)
end
context 'when load balancing is enabled' do
before do
allow(Gitlab::Database::LoadBalancing).to receive(:enable?).and_return(true)
end
it 'reads from the primary database' do
expect(Gitlab::Database::LoadBalancing::Session.current)
.to receive(:use_primary!)
execute_worker
end
end
end
end
end
......@@ -11,7 +11,7 @@ RSpec.describe AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker do
it_behaves_like 'worker with data consistency',
described_class,
feature_flag: :periodic_project_authorization_update_via_replica,
feature_flag: :delayed_consistency_for_user_refresh_over_range_worker,
data_consistency: :delayed
describe '#perform' do
......
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