Class: UltraMarathon::CollectionRunner
- Inherits:
-
BaseRunner
- Object
- BaseRunner
- UltraMarathon::CollectionRunner
- Defined in:
- lib/ultra_marathon/collection_runner.rb
Constant Summary
Constants inherited from BaseRunner
BaseRunner::RUN_INSTRUMENTATION_NAME
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#run_block ⇒ Object
readonly
Returns the value of attribute run_block.
Attributes inherited from BaseRunner
Instance Method Summary collapse
- #complete? ⇒ Boolean
-
#initialize(collection, options = {}, &run_block) ⇒ CollectionRunner
constructor
Takes a collection, each of which will be run in its own subrunner.
-
#parents ⇒ Object
Set of all sub runners that should be run before this one.
- #threaded? ⇒ Boolean
- #unrun_sub_runners ⇒ Object
Methods inherited from BaseRunner
new, #reset, #run!, #run_instrumentation, #success?
Methods included from Contexticution
Methods included from Instrumentation
Methods included from Logging
Constructor Details
#initialize(collection, options = {}, &run_block) ⇒ CollectionRunner
Takes a collection, each of which will be run in its own subrunner. The collection Also takes a number of options:
name: The name of the collection run block sub_name: A callable object (passed the index of the collection) that
should return a unique (to the collection) name for that subrunner
Defaults to :"#{options[:name]}__#{index}"
sub_runner: Class inheiriting from UltraMarathon::SubRunner in which each
run_block will be run
Defaults to UltraMarathon::SubRunner
iterator: Method called to iterate over collection. For example, a Rails
application may wish to use :find_each with an ActiveRecord::Relation
to batch queries
Defaults to :each
threaded: Run each iteration in its own thread
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ultra_marathon/collection_runner.rb', line 32 def initialize(collection, ={}, &run_block) @collection, @run_block = collection, run_block @name = [:name] @options = { sub_name: proc { |index| :"#{[:name]}__#{index}" }, sub_runner: SubRunner, iterator: :each, threaded: false }.merge() end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
9 10 11 |
# File 'lib/ultra_marathon/collection_runner.rb', line 9 def collection @collection end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/ultra_marathon/collection_runner.rb', line 9 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/ultra_marathon/collection_runner.rb', line 9 def @options end |
#run_block ⇒ Object (readonly)
Returns the value of attribute run_block.
9 10 11 |
# File 'lib/ultra_marathon/collection_runner.rb', line 9 def run_block @run_block end |
Instance Method Details
#complete? ⇒ Boolean
60 61 62 |
# File 'lib/ultra_marathon/collection_runner.rb', line 60 def complete? unrun_sub_runners.empty? && running_sub_runners.empty? 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.
67 68 69 |
# File 'lib/ultra_marathon/collection_runner.rb', line 67 def parents @parents ||= Set.new([:requires]) end |
#threaded? ⇒ Boolean
56 57 58 |
# File 'lib/ultra_marathon/collection_runner.rb', line 56 def threaded? false end |
#unrun_sub_runners ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ultra_marathon/collection_runner.rb', line 43 def unrun_sub_runners @unrun_sub_runners ||= begin store = Store.new index = 0 collection.send([:iterator]) do |item| this_index = index index += 1 store << new_item_sub_runner(item, this_index) end store end end |