summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-24 12:09:01 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-24 12:09:01 +0000
commit2c2dd5e36c4ed5f09f488be288882d98f9124d12 (patch)
treead4c478bb1c588387a881b26a7db7c3237b9d4f3 /lib
parent2ff184ad761fbfbe25a3d827c8f704349963a8d2 (diff)
downloadgitlab-ce-2c2dd5e36c4ed5f09f488be288882d98f9124d12.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/api/groups.rb16
-rw-r--r--lib/gitlab/application_context.rb6
-rw-r--r--lib/gitlab/sidekiq_middleware.rb1
-rw-r--r--lib/gitlab/sidekiq_middleware/worker_context/server.rb27
4 files changed, 43 insertions, 7 deletions
diff --git a/lib/api/groups.rb b/lib/api/groups.rb
index 52fa3f8a68e..d375c35e8c0 100644
--- a/lib/api/groups.rb
+++ b/lib/api/groups.rb
@@ -92,6 +92,15 @@ module API
present paginate(groups), options
end
+
+ def delete_group(group)
+ Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-foss/issues/46285')
+ destroy_conditionally!(group) do |group|
+ ::Groups::DestroyService.new(group, current_user).async_execute
+ end
+
+ accepted!
+ end
end
resource :groups do
@@ -187,12 +196,7 @@ module API
group = find_group!(params[:id])
authorize! :admin_group, group
- Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-foss/issues/46285')
- destroy_conditionally!(group) do |group|
- ::Groups::DestroyService.new(group, current_user).async_execute
- end
-
- accepted!
+ delete_group(group)
end
desc 'Get a list of projects in this group.' do
diff --git a/lib/gitlab/application_context.rb b/lib/gitlab/application_context.rb
index 5a9a99423c4..b950bfb0f3a 100644
--- a/lib/gitlab/application_context.rb
+++ b/lib/gitlab/application_context.rb
@@ -16,7 +16,7 @@ module Gitlab
def self.with_context(args, &block)
application_context = new(**args)
- Labkit::Context.with_context(application_context.to_lazy_hash, &block)
+ application_context.use(&block)
end
def self.push(args)
@@ -42,6 +42,10 @@ module Gitlab
end
end
+ def use
+ Labkit::Context.with_context(to_lazy_hash) { yield }
+ end
+
private
attr_reader :set_values
diff --git a/lib/gitlab/sidekiq_middleware.rb b/lib/gitlab/sidekiq_middleware.rb
index 3dda244233f..b19853a1702 100644
--- a/lib/gitlab/sidekiq_middleware.rb
+++ b/lib/gitlab/sidekiq_middleware.rb
@@ -18,6 +18,7 @@ module Gitlab
chain.add Labkit::Middleware::Sidekiq::Server
chain.add Gitlab::SidekiqMiddleware::InstrumentationLogger
chain.add Gitlab::SidekiqStatus::ServerMiddleware
+ chain.add Gitlab::SidekiqMiddleware::WorkerContext::Server
end
end
diff --git a/lib/gitlab/sidekiq_middleware/worker_context/server.rb b/lib/gitlab/sidekiq_middleware/worker_context/server.rb
new file mode 100644
index 00000000000..29d98ad16a9
--- /dev/null
+++ b/lib/gitlab/sidekiq_middleware/worker_context/server.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module SidekiqMiddleware
+ module WorkerContext
+ class Server
+ def call(worker, job, _queue, &block)
+ worker_class = worker.class
+
+ # This is not a worker we know about, perhaps from a gem
+ return yield unless worker_class.respond_to?(:get_worker_context)
+
+ # Use the context defined on the class level as a base context
+ wrap_in_optional_context(worker_class.get_worker_context, &block)
+ end
+
+ private
+
+ def wrap_in_optional_context(context, &block)
+ return yield unless context
+
+ context.use(&block)
+ end
+ end
+ end
+ end
+end