9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/sidekiq/circuit_breaker/middleware.rb', line 9
def call(worker_class, msg, queue, redis_pool)
begin
worker = constantize(worker_class)
rescue NameError
return yield
end
circuit_breaker = worker.respond_to?(:sidekiq_circuit_breaker_enabled?)
return yield unless circuit_breaker
options = worker.sidekiq_circuit_breaker_options
scope = (options, msg) || worker_class
mgr = CircuitBreaker::Manager.new(scope, options)
if mgr.open? && msg['at'].nil?
msg['at'] = (Time.now + (mgr.time_to_open + additional_seconds)).to_f
end
yield
end
|