Class: Sc4ry::RunController

Inherits:
Object
  • Object
show all
Defined in:
lib/sc4ry/run_controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_timeObject (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

Returns:

  • (Boolean)


15
16
17
# File 'lib/sc4ry/run_controller.rb', line 15

def failed?
  return @failure
end

#overtimed?Boolean

Returns:

  • (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
55
56
57
58
59
# File 'lib/sc4ry/run_controller.rb', line 28

def run(options = {})
  start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  begin 
    if @circuit[:timeout] == true
      Timeout::timeout(@circuit[:timeout_value]) do 
        options[:block].call
      end
      @timeout = false
    else
      options[: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  
      if @circuit[:forward_unknown_exceptions] then
        raise e.class, "Sc4ry forward: #{e.message}" 
      else
        Sc4ry::Helpers.log level: :debug, message: "skipped : #{@last_exception}"
      end
      
    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

Returns:

  • (Boolean)


23
24
25
# File 'lib/sc4ry/run_controller.rb', line 23

def timeout? 
  return @timeout
end