lib/sidekiq/circuit_breaker/middleware.rb in sidekiq-circuit-breaker-0.1.1 vs lib/sidekiq/circuit_breaker/middleware.rb in sidekiq-circuit-breaker-0.1.2
- old
+ new
@@ -5,22 +5,33 @@
module Sidekiq
module CircuitBreaker
module Middleware
class Client
def call(worker_class, msg, queue, redis_pool)
- worker = constantize(worker_class)
+ 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 = extract_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 + rand(10)).to_f
+ msg['at'] = (Time.now + (mgr.time_to_open + additional_seconds)).to_f
end
yield
+ end
+
+ private
+
+ def additional_seconds
+ rand(3..10)
end
private
def extract_scope(options, msg)