Fix RuboCop style violations in circuit_breaker.rb

This commit is contained in:
Mahima Singh 2025-12-26 17:09:57 +05:30
parent efc31a3280
commit 07a73d68ae

View file

@ -9,7 +9,7 @@ module Vmpooler
# - OPEN: Provider is failing, reject requests immediately (fail fast)
# - HALF_OPEN: Testing if provider has recovered with limited requests
class CircuitBreaker
STATES = [:closed, :open, :half_open].freeze
STATES = %i[closed open half_open].freeze
class CircuitOpenError < StandardError; end
@ -133,9 +133,7 @@ module Vmpooler
@failure_count = 0
@logger.log('d', "[+] [circuit_breaker] '#{@name}' successful test request (#{@success_count}/#{@half_open_attempts})")
if @success_count >= @half_open_attempts
transition_to_closed
end
transition_to_closed if @success_count >= @half_open_attempts
when :open
# Should not happen, but reset if we somehow get a success
transition_to_closed
@ -151,9 +149,7 @@ module Vmpooler
case @state
when :closed
@logger.log('d', "[!] [circuit_breaker] '#{@name}' failure #{@failure_count}/#{@failure_threshold}: #{error.class}")
if @failure_count >= @failure_threshold
transition_to_open
end
transition_to_open if @failure_count >= @failure_threshold
when :half_open
@logger.log('d', "[!] [circuit_breaker] '#{@name}' failed during half-open test")
transition_to_open