diff --git a/changelogs/unreleased/dm-batch-loader-sidekiq.yml b/changelogs/unreleased/dm-batch-loader-sidekiq.yml new file mode 100644 index 00000000000..87936dc2603 --- /dev/null +++ b/changelogs/unreleased/dm-batch-loader-sidekiq.yml @@ -0,0 +1,5 @@ +--- +title: Clear BatchLoader context between Sidekiq jobs +merge_request: 23308 +author: +type: fixed diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index 565efc858d1..4210be2c701 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -20,6 +20,7 @@ Sidekiq.configure_server do |config| chain.add Gitlab::SidekiqMiddleware::ArgumentsLogger if ENV['SIDEKIQ_LOG_ARGUMENTS'] && !enable_json_logs chain.add Gitlab::SidekiqMiddleware::Shutdown chain.add Gitlab::SidekiqMiddleware::RequestStoreMiddleware unless ENV['SIDEKIQ_REQUEST_STORE'] == '0' + chain.add Gitlab::SidekiqMiddleware::BatchLoader chain.add Gitlab::SidekiqStatus::ServerMiddleware end diff --git a/lib/gitlab/sidekiq_middleware/batch_loader.rb b/lib/gitlab/sidekiq_middleware/batch_loader.rb new file mode 100644 index 00000000000..75c4efc3042 --- /dev/null +++ b/lib/gitlab/sidekiq_middleware/batch_loader.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Gitlab + module SidekiqMiddleware + class BatchLoader + def call(worker, job, queue) + yield + ensure + ::BatchLoader::Executor.clear_current + end + end + end +end