Commit 7c2e4a6c authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Wrap Sidekiq scheduler threads in Rails reloader

We execute DB queries in our Sidekiq client middleware so this is needed
to properly checkin DB connections after every poll. On the next poll, a
new connection will be checked out and a connection check query will be
executed. Rails would then handle the reconnection for us in case the
connection is bad.

Without this, we would continue using a bad connection until Sidekiq is
restarted.

Changelog: fixed
parent 22cb2366
......@@ -116,3 +116,4 @@ Sidekiq.configure_client do |config|
end
Sidekiq::Client.prepend Gitlab::Patch::SidekiqClient
Sidekiq::Cron::Poller.prepend Gitlab::Patch::SidekiqCronPoller
# frozen_string_literal: true
module Gitlab
module Patch
module SidekiqCronPoller
def enqueue
Rails.application.reloader.wrap do
::Gitlab::WithRequestStore.with_request_store do
super
ensure
::Gitlab::Database::LoadBalancing.release_hosts
end
end
end
end
end
end
......@@ -14,10 +14,17 @@ module Gitlab
LUA_ZPOPBYSCORE_SHA = Digest::SHA1.hexdigest(LUA_ZPOPBYSCORE)
def enqueue_jobs(now = Time.now.to_f.to_s, sorted_sets = Sidekiq::Scheduled::SETS)
if Feature.enabled?(:atomic_sidekiq_scheduler, default_enabled: :yaml)
atomic_find_jobs_and_enqueue(now, sorted_sets)
else
find_jobs_and_enqueue(now, sorted_sets)
Rails.application.reloader.wrap do
::Gitlab::WithRequestStore.with_request_store do
if Feature.enabled?(:atomic_sidekiq_scheduler, default_enabled: :yaml)
atomic_find_jobs_and_enqueue(now, sorted_sets)
else
find_jobs_and_enqueue(now, sorted_sets)
end
ensure
::Gitlab::Database::LoadBalancing.release_hosts
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment