gitlab-org--gitlab-foss/app/services/user_project_access_changed_service.rb

32 lines
912 B
Ruby

# frozen_string_literal: true
class UserProjectAccessChangedService
DELAY = 1.hour
HIGH_PRIORITY = :high
LOW_PRIORITY = :low
def initialize(user_ids)
@user_ids = Array.wrap(user_ids)
end
def execute(blocking: true, priority: HIGH_PRIORITY)
bulk_args = @user_ids.map { |id| [id] }
result =
if blocking
AuthorizedProjectsWorker.bulk_perform_and_wait(bulk_args)
else
if priority == HIGH_PRIORITY
AuthorizedProjectsWorker.bulk_perform_async(bulk_args) # rubocop:disable Scalability/BulkPerformWithContext
else
AuthorizedProjectUpdate::UserRefreshWithLowUrgencyWorker.bulk_perform_in( # rubocop:disable Scalability/BulkPerformWithContext
DELAY, bulk_args, batch_size: 100, batch_delay: 30.seconds)
end
end
::Gitlab::Database::LoadBalancing::Sticking.bulk_stick(:user, @user_ids)
result
end
end