lib/sidekiq/circuit_breaker/middleware.rb in sidekiq-circuit-breaker-0.1.0 vs lib/sidekiq/circuit_breaker/middleware.rb in sidekiq-circuit-breaker-0.1.1
- old
+ new
@@ -14,11 +14,11 @@
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).to_f
+ msg['at'] = (Time.now + mgr.time_to_open + rand(10)).to_f
end
yield
end
@@ -41,12 +41,12 @@
end
end
class Server
def call(worker, msg, queue)
- circuit_breaker_enabled = worker.respond_to?(:sidekiq_circuit_breaker_enabled?)
- return unless circuit_breaker_enabled
+ circuit_breaker_enabled = worker.class.respond_to?(:sidekiq_circuit_breaker_enabled?)
+ return yield unless circuit_breaker_enabled
def worker.perform(*args)
manager = sidekiq_circuit_breaker_manager(args)
if manager.open?
@@ -60,15 +60,14 @@
end
super(*args)
end
- options = worker.class.sidekiq_circuit_breaker_options
- manager = worker.sidekiq_circuit_breaker_manager(args, options)
+ manager = worker.sidekiq_circuit_breaker_manager(msg['args'])
begin
yield
- rescue Exception => e
+ rescue => e
manager.evaluate_failure
raise e
end
manager.register_success