Class: CircuitSwitch::Core
- Inherits:
-
Object
- Object
- CircuitSwitch::Core
- Defined in:
- lib/circuit_switch/core.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#close_if ⇒ Object
readonly
Returns the value of attribute close_if.
-
#close_if_reach_limit ⇒ Object
readonly
Returns the value of attribute close_if_reach_limit.
-
#initially_closed ⇒ Object
readonly
Returns the value of attribute initially_closed.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#report_if ⇒ Object
readonly
Returns the value of attribute report_if.
-
#report_limit_count ⇒ Object
readonly
Returns the value of attribute report_limit_count.
-
#run_if ⇒ Object
readonly
Returns the value of attribute run_if.
-
#run_limit_count ⇒ Object
readonly
Returns the value of attribute run_limit_count.
-
#stop_report_if ⇒ Object
readonly
Returns the value of attribute stop_report_if.
-
#stop_report_if_reach_limit ⇒ Object
readonly
Returns the value of attribute stop_report_if_reach_limit.
Instance Method Summary collapse
Instance Attribute Details
#close_if ⇒ Object (readonly)
Returns the value of attribute close_if.
8 9 10 |
# File 'lib/circuit_switch/core.rb', line 8 def close_if @close_if end |
#close_if_reach_limit ⇒ Object (readonly)
Returns the value of attribute close_if_reach_limit.
8 9 10 |
# File 'lib/circuit_switch/core.rb', line 8 def close_if_reach_limit @close_if_reach_limit end |
#initially_closed ⇒ Object (readonly)
Returns the value of attribute initially_closed.
8 9 10 |
# File 'lib/circuit_switch/core.rb', line 8 def initially_closed @initially_closed end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
8 9 10 |
# File 'lib/circuit_switch/core.rb', line 8 def key @key end |
#report_if ⇒ Object (readonly)
Returns the value of attribute report_if.
8 9 10 |
# File 'lib/circuit_switch/core.rb', line 8 def report_if @report_if end |
#report_limit_count ⇒ Object (readonly)
Returns the value of attribute report_limit_count.
8 9 10 |
# File 'lib/circuit_switch/core.rb', line 8 def report_limit_count @report_limit_count end |
#run_if ⇒ Object (readonly)
Returns the value of attribute run_if.
8 9 10 |
# File 'lib/circuit_switch/core.rb', line 8 def run_if @run_if end |
#run_limit_count ⇒ Object (readonly)
Returns the value of attribute run_limit_count.
8 9 10 |
# File 'lib/circuit_switch/core.rb', line 8 def run_limit_count @run_limit_count end |
#stop_report_if ⇒ Object (readonly)
Returns the value of attribute stop_report_if.
8 9 10 |
# File 'lib/circuit_switch/core.rb', line 8 def stop_report_if @stop_report_if end |
#stop_report_if_reach_limit ⇒ Object (readonly)
Returns the value of attribute stop_report_if_reach_limit.
8 9 10 |
# File 'lib/circuit_switch/core.rb', line 8 def stop_report_if_reach_limit @stop_report_if_reach_limit end |
Instance Method Details
#execute_report ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/circuit_switch/core.rb', line 43 def execute_report if config.reporter.nil? raise CircuitSwitchError.new('Set config.reporter.') end if config.reporter.arity == 1 Logger.new($stdout).info('config.reporter now receives 2 arguments. Improve your `config/initialzers/circuit_switch.rb`.') end if stop_report_if_reach_limit && report_limit_count == 0 raise CircuitSwitchError.new('Can\'t set limit_count to 0 when stop_report_if_reach_limit is true') end return self unless config.enable_report? return self if evaluate(stop_report_if) || !evaluate(report_if) return self if switch.report_is_terminated? return self if stop_report_if_reach_limit && switch.reached_report_limit?(report_limit_count) Reporter.perform_later( key: key, limit_count: report_limit_count, called_path: called_path, stacktrace: StacktraceModifier.call(backtrace: caller), run: run? ) @reported = true self end |
#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 38 39 40 41 |
# 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 if close_if_reach_limit.nil? Logger.new($stdout).info('Default value for close_if_reach_limit is modified from true to false at ver 0.2.0.') @close_if_reach_limit = false 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 |
#reported? ⇒ Boolean
75 76 77 |
# File 'lib/circuit_switch/core.rb', line 75 def reported? @reported end |
#run? ⇒ Boolean
70 71 72 |
# File 'lib/circuit_switch/core.rb', line 70 def run? @run end |