Class: Dplyr::TaskRunner
- Inherits:
-
Object
- Object
- Dplyr::TaskRunner
- Includes:
- Dply::Logger
- Defined in:
- lib/dplyr/task_runner.rb
Instance Attribute Summary collapse
-
#auto_serialize ⇒ Object
writeonly
Sets the attribute auto_serialize.
-
#exit_statuses ⇒ Object
readonly
Returns the value of attribute exit_statuses.
-
#hosts ⇒ Object
readonly
Returns the value of attribute hosts.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
-
#parallel_jobs ⇒ Object
readonly
Returns the value of attribute parallel_jobs.
-
#task ⇒ Object
readonly
Returns the value of attribute task.
Instance Method Summary collapse
-
#initialize(hosts, task, parallel_jobs: 1) ⇒ TaskRunner
constructor
A new instance of TaskRunner.
- #run ⇒ Object
- #run_in_parallel ⇒ Object
- #run_serially ⇒ Object
Methods included from Dply::Logger
#debug?, #logger, stderr, #stderr
Constructor Details
#initialize(hosts, task, parallel_jobs: 1) ⇒ TaskRunner
Returns a new instance of TaskRunner.
14 15 16 17 18 19 20 21 22 |
# File 'lib/dplyr/task_runner.rb', line 14 def initialize(hosts, task, parallel_jobs: 1) @hosts = hosts @parallel_jobs = parallel_jobs @task = task = {} @exit_statuses = {} @auto_serialize = true end |
Instance Attribute Details
#auto_serialize=(value) ⇒ Object (writeonly)
Sets the attribute auto_serialize
12 13 14 |
# File 'lib/dplyr/task_runner.rb', line 12 def auto_serialize=(value) @auto_serialize = value end |
#exit_statuses ⇒ Object (readonly)
Returns the value of attribute exit_statuses.
11 12 13 |
# File 'lib/dplyr/task_runner.rb', line 11 def exit_statuses @exit_statuses end |
#hosts ⇒ Object (readonly)
Returns the value of attribute hosts.
11 12 13 |
# File 'lib/dplyr/task_runner.rb', line 11 def hosts @hosts end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
11 12 13 |
# File 'lib/dplyr/task_runner.rb', line 11 def end |
#parallel_jobs ⇒ Object (readonly)
Returns the value of attribute parallel_jobs.
11 12 13 |
# File 'lib/dplyr/task_runner.rb', line 11 def parallel_jobs @parallel_jobs end |
#task ⇒ Object (readonly)
Returns the value of attribute task.
11 12 13 |
# File 'lib/dplyr/task_runner.rb', line 11 def task @task end |
Instance Method Details
#run ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/dplyr/task_runner.rb', line 24 def run raise ::Dply::Error, "no hosts found" if hosts.empty? if parallel_jobs > 1 && hosts.count > 1 run_in_parallel else run_serially end report.print_full end |
#run_in_parallel ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/dplyr/task_runner.rb', line 41 def run_in_parallel if @auto_serialize t = execute_serially hosts[0] return if t.exit_status != 0 execute_in_parallel Range.new(1,hosts.size - 1) else execute_in_parallel Range.new(0, hosts.size - 1) end end |
#run_serially ⇒ Object
34 35 36 37 38 39 |
# File 'lib/dplyr/task_runner.rb', line 34 def run_serially hosts.each do |host| task = execute_serially host break if task.exit_status != 0 end end |