summaryrefslogtreecommitdiff
path: root/app/workers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-07-15 21:09:09 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-07-15 21:09:09 +0000
commitd1377e82d9bccd6b49c08aa67f6776b7981295ae (patch)
tree0a02a1b531d6e8097efc11468303bffbd0f18af5 /app/workers
parentd811b6d8f61b45cd12f94251abff9102b8cefc19 (diff)
downloadgitlab-ce-d1377e82d9bccd6b49c08aa67f6776b7981295ae.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/all_queues.yml2
-rw-r--r--app/workers/authorized_project_update/user_refresh_from_replica_worker.rb35
2 files changed, 21 insertions, 16 deletions
diff --git a/app/workers/all_queues.yml b/app/workers/all_queues.yml
index de1b17b588f..8d08beb56aa 100644
--- a/app/workers/all_queues.yml
+++ b/app/workers/all_queues.yml
@@ -37,7 +37,7 @@
:urgency: :low
:resource_boundary: :unknown
:weight: 1
- :idempotent:
+ :idempotent: true
:tags: []
- :name: authorized_project_update:authorized_project_update_user_refresh_over_user_range
:worker_name: AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker
diff --git a/app/workers/authorized_project_update/user_refresh_from_replica_worker.rb b/app/workers/authorized_project_update/user_refresh_from_replica_worker.rb
index 7ce3f5453d2..10f7cb20df0 100644
--- a/app/workers/authorized_project_update/user_refresh_from_replica_worker.rb
+++ b/app/workers/authorized_project_update/user_refresh_from_replica_worker.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module AuthorizedProjectUpdate
- class UserRefreshFromReplicaWorker # rubocop:disable Scalability/IdempotentWorker
+ class UserRefreshFromReplicaWorker
include ApplicationWorker
sidekiq_options retry: 3
@@ -9,31 +9,36 @@ module AuthorizedProjectUpdate
urgency :low
queue_namespace :authorized_project_update
- # This job will not be deduplicated since it is marked with
- # `data_consistency :delayed` and not `idempotent!`
- # See https://gitlab.com/gitlab-org/gitlab/-/issues/325291
+ idempotent!
deduplicate :until_executing, including_scheduled: true
- data_consistency :delayed
-
def perform(user_id)
- user = User.find_by_id(user_id)
- return unless user
-
if Feature.enabled?(:user_refresh_from_replica_worker_uses_replica_db)
- enqueue_project_authorizations_refresh(user) if project_authorizations_needs_refresh?(user)
+ use_replica_if_available do
+ user = User.find_by_id(user_id)
+
+ if user && project_authorizations_needs_refresh?(user)
+ enqueue_project_authorizations_refresh(user)
+ end
+ end
else
- use_primary_database
+ user = User.find_by_id(user_id)
+ return unless user
+
user.refresh_authorized_projects(source: self.class.name)
end
end
private
- def use_primary_database
- if ::Gitlab::Database::LoadBalancing.enable?
- ::Gitlab::Database::LoadBalancing::Session.current.use_primary!
- end
+ # We use this approach instead of specifying `data_consistency :delayed` because these jobs
+ # are enqueued in large numbers, and using `data_consistency :delayed`
+ # does not allow us to deduplicate these jobs.
+ # https://gitlab.com/gitlab-org/gitlab/-/issues/325291
+ def use_replica_if_available(&block)
+ return yield unless ::Gitlab::Database::LoadBalancing.enable?
+
+ ::Gitlab::Database::LoadBalancing::Session.current.use_replicas_for_read_queries(&block)
end
def project_authorizations_needs_refresh?(user)