Method: CircuitSwitch::Core#execute_run

Defined in:
lib/circuit_switch/core.rb

#execute_run(&block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/circuit_switch/core.rb', line 11

def execute_run(&block)
  run_executable = false
  if close_if_reach_limit && run_limit_count == 0
    raise CircuitSwitchError.new('Can\'t set limit_count to 0 when close_if_reach_limit is true')
  end

  return self if evaluate(close_if) || !evaluate(run_if)
  return self if close_if_reach_limit && switch.reached_run_limit?(run_limit_count)
  return self if switch.run_is_terminated?

  run_executable = true
  unless switch.new_record? && initially_closed
    yield
    @run = true
  end
  self
ensure
  if run_executable
    RunCountUpdater.perform_later(
      key: key,
      limit_count: run_limit_count,
      called_path: called_path,
      reported: reported?,
      initially_closed: initially_closed
    )
  end
end