Class: Tomo::Runtime::ExecutionPlan
- Inherits:
-
Object
- Object
- Tomo::Runtime::ExecutionPlan
- Extended by:
- Forwardable
- Defined in:
- lib/tomo/runtime/execution_plan.rb
Instance Attribute Summary collapse
-
#applicable_hosts ⇒ Object
readonly
Returns the value of attribute applicable_hosts.
Instance Method Summary collapse
- #applicable_hosts_sentence ⇒ Object
- #execute ⇒ Object
- #explain ⇒ Object
-
#initialize(tasks:, hosts:, task_filter:, task_runner:) ⇒ ExecutionPlan
constructor
A new instance of ExecutionPlan.
Constructor Details
#initialize(tasks:, hosts:, task_filter:, task_runner:) ⇒ ExecutionPlan
Returns a new instance of ExecutionPlan.
14 15 16 17 18 19 20 21 22 |
# File 'lib/tomo/runtime/execution_plan.rb', line 14 def initialize(tasks:, hosts:, task_filter:, task_runner:) @hosts = hosts @task_runner = task_runner @plan = build_plan(tasks, task_filter) @applicable_hosts = gather_applicable_hosts @thread_pool = build_thread_pool freeze validate_tasks! end |
Instance Attribute Details
#applicable_hosts ⇒ Object (readonly)
Returns the value of attribute applicable_hosts.
12 13 14 |
# File 'lib/tomo/runtime/execution_plan.rb', line 12 def applicable_hosts @applicable_hosts end |
Instance Method Details
#applicable_hosts_sentence ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/tomo/runtime/execution_plan.rb', line 24 def applicable_hosts_sentence return "no hosts" if applicable_hosts.empty? case applicable_hosts.length when 1 then applicable_hosts.first.to_s when 2 then applicable_hosts.map(&:to_s).join(" and ") else "#{applicable_hosts.first} and #{applicable_hosts.length - 1} other hosts" end end |
#execute ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tomo/runtime/execution_plan.rb', line 35 def execute Tomo.logger.debug("Execution plan:\n#{explain}") open_connections do |remotes| plan.each do |steps| steps.each do |step| step.execute(thread_pool:, remotes:) end thread_pool.run_to_completion end end self end |
#explain ⇒ Object
48 49 50 |
# File 'lib/tomo/runtime/execution_plan.rb', line 48 def explain Explanation.new(applicable_hosts, plan, concurrency).to_s end |