Class: Tomo::Runtime::ExecutionPlan

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/tomo/runtime/execution_plan.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_hostsObject (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_sentenceObject



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

#executeObject



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

#explainObject



48
49
50
# File 'lib/tomo/runtime/execution_plan.rb', line 48

def explain
  Explanation.new(applicable_hosts, plan, concurrency).to_s
end