summaryrefslogtreecommitdiff
path: root/app/workers
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2017-08-28 12:21:17 +0000
committerDouwe Maan <douwe@gitlab.com>2017-08-28 12:21:17 +0000
commit0b73771205a2f967055c9701ff92f70289a1af23 (patch)
treef1f51d5596c700b17318e1932ca9ce0b02d94b31 /app/workers
parented1ca47c9ea893d643ae613f39b65d80db3b0e67 (diff)
parent0a1160e5d7d8234fa9e88038608a37c0f7fe2b05 (diff)
downloadgitlab-ce-0b73771205a2f967055c9701ff92f70289a1af23.tar.gz
Merge branch '36792-inline-user-refresh-when-creating-project' into 'master'
Don't wait for project authorization sidekiq jobs when creating projects Closes #36792 See merge request !13775
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/authorized_projects_worker.rb22
1 files changed, 21 insertions, 1 deletions
diff --git a/app/workers/authorized_projects_worker.rb b/app/workers/authorized_projects_worker.rb
index be4c77503bb..55d8d0c69d1 100644
--- a/app/workers/authorized_projects_worker.rb
+++ b/app/workers/authorized_projects_worker.rb
@@ -4,20 +4,40 @@ class AuthorizedProjectsWorker
# Schedules multiple jobs and waits for them to be completed.
def self.bulk_perform_and_wait(args_list)
+ # Short-circuit: it's more efficient to do small numbers of jobs inline
+ return bulk_perform_inline(args_list) if args_list.size <= 3
+
waiter = Gitlab::JobWaiter.new(args_list.size)
# Point all the bulk jobs at the same JobWaiter. Converts, [[1], [2], [3]]
# into [[1, "key"], [2, "key"], [3, "key"]]
- waiting_args_list = args_list.map { |args| args << waiter.key }
+ waiting_args_list = args_list.map { |args| [*args, waiter.key] }
bulk_perform_async(waiting_args_list)
waiter.wait
end
+ # Schedules multiple jobs to run in sidekiq without waiting for completion
def self.bulk_perform_async(args_list)
Sidekiq::Client.push_bulk('class' => self, 'queue' => sidekiq_options['queue'], 'args' => args_list)
end
+ # Performs multiple jobs directly. Failed jobs will be put into sidekiq so
+ # they can benefit from retries
+ def self.bulk_perform_inline(args_list)
+ failed = []
+
+ args_list.each do |args|
+ begin
+ new.perform(*args)
+ rescue
+ failed << args
+ end
+ end
+
+ bulk_perform_async(failed) if failed.present?
+ end
+
def perform(user_id, notify_key = nil)
user = User.find_by(id: user_id)