Class: UltraMarathon::SubRunner
- Includes:
- Callbacks, Instrumentation, Logging
- Defined in:
- lib/ultra_marathon/sub_runner.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#run_block_or_sub_context ⇒ Object
readonly
Returns the value of attribute run_block_or_sub_context.
-
#run_thread ⇒ Object
Returns the value of attribute run_thread.
-
#success ⇒ Object
Returns the value of attribute success.
Instance Method Summary collapse
-
#complete? ⇒ Boolean
Tells whether the runner has completed.
-
#initialize(options, run_block_or_sub_context) ⇒ SubRunner
constructor
The :context option is required, because you’ll never want to run a SubRunner in context of itself.
-
#parents ⇒ Set
Set of all sub runners that should be run before this one, as specified by the :requires option.
-
#reset ⇒ self
Invokes all on_reset callbacks.
-
#run! ⇒ self
Run the run block or sub context.
-
#running? ⇒ Boolean
If #threaded?, returns if the run_thread is alive.
-
#threaded? ⇒ Boolean
Whether #run! will be executed in a thread.
Methods included from Logging
Methods included from Instrumentation
Methods included from Contexticution
Constructor Details
#initialize(options, run_block_or_sub_context) ⇒ 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.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ultra_marathon/sub_runner.rb', line 47 def initialize(, run_block_or_sub_context) @run_block_or_sub_context = run_block_or_sub_context @name = .delete(:name) @options = { instrument: false, threaded: false, requires: Set.new, timeout: 100 }.merge() end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/ultra_marathon/sub_runner.rb', line 14 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/ultra_marathon/sub_runner.rb', line 14 def @options end |
#run_block_or_sub_context ⇒ Object (readonly)
Returns the value of attribute run_block_or_sub_context.
14 15 16 |
# File 'lib/ultra_marathon/sub_runner.rb', line 14 def run_block_or_sub_context @run_block_or_sub_context end |
#run_thread ⇒ Object
Returns the value of attribute run_thread.
13 14 15 |
# File 'lib/ultra_marathon/sub_runner.rb', line 13 def run_thread @run_thread end |
#success ⇒ Object
Returns the value of attribute success.
13 14 15 |
# File 'lib/ultra_marathon/sub_runner.rb', line 13 def success @success end |
Instance Method Details
#complete? ⇒ Boolean
Tells whether the runner has completed. If running in a threaded context, checks if the thread is alive. Otherwise, returns true.
74 75 76 77 78 79 80 |
# File 'lib/ultra_marathon/sub_runner.rb', line 74 def complete? if threaded? !running? else true end end |
#parents ⇒ Set
Set of all sub runners that should be run before this one, as specified by the :requires option.
107 108 109 |
# File 'lib/ultra_marathon/sub_runner.rb', line 107 def parents @parents ||= Set.new([:requires]) end |
#reset ⇒ self
Invokes all on_reset callbacks
99 100 101 102 |
# File 'lib/ultra_marathon/sub_runner.rb', line 99 def reset invoke_on_reset_callbacks self end |
#run! ⇒ self
Run the run block or sub context. If #threaded? is true, will envelope the run in a thread and immediately return. If there is already an active thread, it will not run again.
62 63 64 65 66 67 68 69 |
# File 'lib/ultra_marathon/sub_runner.rb', line 62 def run! if threaded? run_in_thread else run_without_thread end self end |
#running? ⇒ Boolean
If #threaded?, returns if the run_thread is alive. Otherwise false.
84 85 86 87 88 89 90 |
# File 'lib/ultra_marathon/sub_runner.rb', line 84 def running? if threaded? run_thread && run_thread.alive? else false end end |
#threaded? ⇒ Boolean
Returns whether #run! will be executed in a thread.
93 94 95 |
# File 'lib/ultra_marathon/sub_runner.rb', line 93 def threaded? !![:threaded] end |