debian-mirror-gitlab/app/services/user_project_access_changed_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.7 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
class UserProjectAccessChangedService
2020-05-24 23:13:21 +05:30
DELAY = 1.hour
2022-07-23 23:45:48 +05:30
MEDIUM_DELAY = 10.minutes
2020-05-24 23:13:21 +05:30
HIGH_PRIORITY = :high
2022-07-23 23:45:48 +05:30
MEDIUM_PRIORITY = :medium
2020-05-24 23:13:21 +05:30
LOW_PRIORITY = :low
2017-08-17 22:00:37 +05:30
def initialize(user_ids)
@user_ids = Array.wrap(user_ids)
end
2020-05-24 23:13:21 +05:30
def execute(blocking: true, priority: HIGH_PRIORITY)
2022-07-23 23:45:48 +05:30
return if @user_ids.empty?
2018-03-17 18:26:18 +05:30
bulk_args = @user_ids.map { |id| [id] }
2021-09-04 01:27:46 +05:30
result =
if blocking
AuthorizedProjectsWorker.bulk_perform_and_wait(bulk_args)
2020-05-24 23:13:21 +05:30
else
2023-01-13 00:05:48 +05:30
case priority
when HIGH_PRIORITY
2021-09-04 01:27:46 +05:30
AuthorizedProjectsWorker.bulk_perform_async(bulk_args) # rubocop:disable Scalability/BulkPerformWithContext
2023-01-13 00:05:48 +05:30
when MEDIUM_PRIORITY
2022-07-23 23:45:48 +05:30
AuthorizedProjectUpdate::UserRefreshWithLowUrgencyWorker.bulk_perform_in(MEDIUM_DELAY, bulk_args, batch_size: 100, batch_delay: 30.seconds) # rubocop:disable Scalability/BulkPerformWithContext
2021-09-04 01:27:46 +05:30
else
2021-09-30 23:02:18 +05:30
with_related_class_context do
# We wrap the execution in `with_related_class_context`so as to obtain
# the location of the original caller
# in jobs enqueued from within `AuthorizedProjectUpdate::UserRefreshFromReplicaWorker`
AuthorizedProjectUpdate::UserRefreshFromReplicaWorker.bulk_perform_in( # rubocop:disable Scalability/BulkPerformWithContext
DELAY, bulk_args, batch_size: 100, batch_delay: 30.seconds)
end
2021-09-04 01:27:46 +05:30
end
2020-05-24 23:13:21 +05:30
end
2021-09-04 01:27:46 +05:30
2021-11-18 22:05:49 +05:30
::User.sticking.bulk_stick(:user, @user_ids)
2021-09-04 01:27:46 +05:30
result
2017-08-17 22:00:37 +05:30
end
2021-09-30 23:02:18 +05:30
private
def with_related_class_context(&block)
current_caller_id = Gitlab::ApplicationContext.current_context_attribute('meta.caller_id').presence
Gitlab::ApplicationContext.with_context(related_class: current_caller_id, &block)
end
2017-08-17 22:00:37 +05:30
end