Class: Sc4ry::RunController
- Inherits:
-
Object
- Object
- Sc4ry::RunController
- Defined in:
- lib/sc4ry/run_controller.rb
Instance Attribute Summary collapse
-
#execution_time ⇒ Object
readonly
Returns the value of attribute execution_time.
Instance Method Summary collapse
- #failed? ⇒ Boolean
-
#initialize(circuit = {}) ⇒ RunController
constructor
A new instance of RunController.
- #overtimed? ⇒ Boolean
- #run(options = {}) ⇒ Object
- #timeout? ⇒ Boolean
Constructor Details
#initialize(circuit = {}) ⇒ RunController
Returns a new instance of RunController.
7 8 9 10 11 12 13 |
# File 'lib/sc4ry/run_controller.rb', line 7 def initialize(circuit = {}) @circuit = circuit @execution_time = 0 @timeout = false @failure = false @overtime = false end |
Instance Attribute Details
#execution_time ⇒ Object (readonly)
Returns the value of attribute execution_time.
5 6 7 |
# File 'lib/sc4ry/run_controller.rb', line 5 def execution_time @execution_time end |
Instance Method Details
#failed? ⇒ Boolean
15 16 17 |
# File 'lib/sc4ry/run_controller.rb', line 15 def failed? return @failure end |
#overtimed? ⇒ Boolean
19 20 21 |
# File 'lib/sc4ry/run_controller.rb', line 19 def overtimed? return @overtime end |
#run(options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/sc4ry/run_controller.rb', line 28 def run( = {}) start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) begin if @circuit[:timeout] == true Timeout::timeout(@circuit[:timeout_value]) do [:block].call end @timeout = false else [:block].call end rescue Exception => e @last_exception = e.class if e.class == Timeout::Error then @timeout = true elsif @circuit[:exceptions].include? e.class @failure = true else Sc4ry::Loggers.warning "skipped : #{@last_exception}" end end @end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) @execution_time = @end_time - start_time @overtime = @execution_time > @circuit[:max_time] return {failure: @failure, overtime: @overtime, timeout: @timeout, execution_time: @execution_time, end_time: @end_time, last_exception: @last_exception} end |
#timeout? ⇒ Boolean
23 24 25 |
# File 'lib/sc4ry/run_controller.rb', line 23 def timeout? return @timeout end |