Class: UltraMarathon::SubRunner

Inherits:
Object
  • Object
show all
Includes:
Callbacks, Instrumentation, Logging
Defined in:
lib/ultra_marathon/sub_runner.rb

Constant Summary

Constants included from Instrumentation

Instrumentation::TIME_FORMAT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logger

Methods included from Instrumentation

#instrumentations

Constructor Details

#initialize(options, run_block) ⇒ SubRunner

The :context option is required, because you’ll never want to run a SubRunner in context of itself. SubContext is necessary because we want to run in the context of the other class, but do other things (like log) in the context of this one.



25
26
27
28
29
30
31
# File 'lib/ultra_marathon/sub_runner.rb', line 25

def initialize(options, run_block)
  @name = options[:name]
  @options = {
    instrument: false
  }.merge(options)
  @sub_context = SubContext.new(options[:context], run_block)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/ultra_marathon/sub_runner.rb', line 13

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/ultra_marathon/sub_runner.rb', line 13

def options
  @options
end

#run_blockObject

Returns the value of attribute run_block.



12
13
14
# File 'lib/ultra_marathon/sub_runner.rb', line 12

def run_block
  @run_block
end

#sub_contextObject (readonly)

Returns the value of attribute sub_context.



13
14
15
# File 'lib/ultra_marathon/sub_runner.rb', line 13

def sub_context
  @sub_context
end

#successObject

Returns the value of attribute success.



12
13
14
# File 'lib/ultra_marathon/sub_runner.rb', line 12

def success
  @success
end

Instance Method Details

#log_instrumentationObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/ultra_marathon/sub_runner.rb', line 47

def log_instrumentation
  if options[:instrument]
    run_profile = instrumentations[:run]
    logger.info """
    End Time: #{run_profile.formatted_end_time}
    Start Time: #{run_profile.formatted_start_time}
    Total Time: #{run_profile.formatted_total_time}
    """
  end
end

#parentsObject

Set of all sub runners that should be run before this one. This class cannot do anything with this information, but it is useful to the enveloping runner.



65
66
67
# File 'lib/ultra_marathon/sub_runner.rb', line 65

def parents
  @parents ||= Set.new(options[:requires])
end

#resetObject



58
59
60
# File 'lib/ultra_marathon/sub_runner.rb', line 58

def reset
  invoke_on_reset_callbacks
end

#run!Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ultra_marathon/sub_runner.rb', line 33

def run!
  instrument(:run) do
    begin
      self.success = true
      run_sub_context
    rescue StandardError => error
      invoke_on_error_callbacks(error)
    ensure
      invoke_after_run_callbacks
    end
  end
  log_instrumentation
end