lib/spandx/core/circuit.rb in spandx-0.12.2 vs lib/spandx/core/circuit.rb in spandx-0.12.3
- old
+ new
@@ -1,22 +1,26 @@
# frozen_string_literal: true
module Spandx
module Core
class Circuit
- attr_reader :state
+ attr_reader :name, :state, :logger
- def initialize(state: :closed)
+ def initialize(name, state: :closed, logger: Spandx.logger)
+ @name = name
@state = state
+ @logger = logger
end
def attempt
return if open?
open!
result = yield
close!
result
+ ensure
+ logger.debug("#{name} #{state}")
end
def open!
@state = :open
end