lib/sidekiq/circuit_breaker/api.rb in sidekiq-circuit-breaker-0.1.4 vs lib/sidekiq/circuit_breaker/api.rb in sidekiq-circuit-breaker-0.1.5

- old
+ new

@@ -13,10 +13,21 @@ conn.del(failure_key(scope)) end true end + def close_circuit(scope) + raise ArgumentError, 'scope must not be nil' if scope.nil? + Sidekiq.redis do |conn| + conn.del(open_key(scope)) + # reset failure count + conn.del(failure_key(scope)) + end + true + + end + def register_failure_for_scope(scope, ttl = 120) raise ArgumentError, 'scope must not be nil' if scope.nil? key = failure_key(scope) _, failure_count = Sidekiq.redis do |conn| @@ -34,16 +45,16 @@ Sidekiq.redis do |conn| conn.del(failure_key(scope), open_key(scope)) end end - def time_to_open_the_circuit(scope) + def time_to_close_the_circuit(scope) Sidekiq.redis do |conn| conn.ttl(open_key(scope)) end end - def circuit_opened?(scope) + def circuit_open?(scope) Sidekiq.redis do |conn| conn.exists(open_key(scope)) end end