17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/gitlab/database/load_balancing/sidekiq_server_middleware.rb', line 17
def call(worker, job, _queue)
resolved_class = job['wrapped']&.safe_constantize || worker.class
strategy = select_load_balancing_strategy(resolved_class, job)
job['load_balancing_strategy'] = strategy.to_s
if use_primary?(strategy)
::Gitlab::Database::LoadBalancing::SessionMap
.with_sessions(Gitlab::Database::LoadBalancing.base_models)
.use_primary!
elsif strategy == :retry
raise JobReplicaNotUpToDate, "Sidekiq job #{resolved_class} JID-#{job['jid']} couldn't use the replica. "\
"Replica was not up to date."
else
set_per_database_strategy(resolved_class)
end
yield
ensure
clear
end
|