Class: UltraMarathon::SubRunner
- Inherits:
-
Object
- Object
- UltraMarathon::SubRunner
- Includes:
- Callbacks, Instrumentation, Logging
- Defined in:
- lib/ultra_marathon/sub_runner.rb
Constant Summary
Constants included from Instrumentation
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#run_block ⇒ Object
Returns the value of attribute run_block.
-
#sub_context ⇒ Object
readonly
Returns the value of attribute sub_context.
-
#success ⇒ Object
Returns the value of attribute success.
Instance Method Summary collapse
-
#initialize(options, run_block) ⇒ SubRunner
constructor
The :context option is required, because you’ll never want to run a SubRunner in context of itself.
- #log_instrumentation ⇒ Object
-
#parents ⇒ Object
Set of all sub runners that should be run before this one.
- #reset ⇒ Object
- #run! ⇒ Object
Methods included from Logging
Methods included from Instrumentation
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(, run_block) @name = [:name] @options = { instrument: false }.merge() @sub_context = SubContext.new([:context], run_block) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/ultra_marathon/sub_runner.rb', line 13 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/ultra_marathon/sub_runner.rb', line 13 def @options end |
#run_block ⇒ Object
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_context ⇒ Object (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 |
#success ⇒ Object
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_instrumentation ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ultra_marathon/sub_runner.rb', line 47 def log_instrumentation if [: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 |
#parents ⇒ Object
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([:requires]) end |
#reset ⇒ Object
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 |