Class: Tomo::Runtime::HostExecutionStep

Inherits:
Object
  • Object
show all
Defined in:
lib/tomo/runtime/host_execution_step.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tasks:, host:, task_filter:, task_runner:) ⇒ HostExecutionStep

Returns a new instance of HostExecutionStep.



8
9
10
11
12
13
14
15
# File 'lib/tomo/runtime/host_execution_step.rb', line 8

def initialize(tasks:, host:, task_filter:, task_runner:)
  tasks = Array(tasks).flatten
  @host = host
  @task_runner = task_runner
  @applicable_tasks = task_filter.filter(tasks, host: @host).freeze
  @applicable_hosts = compute_applicable_hosts
  freeze
end

Instance Attribute Details

#applicable_hostsObject (readonly)

Returns the value of attribute applicable_hosts.



6
7
8
# File 'lib/tomo/runtime/host_execution_step.rb', line 6

def applicable_hosts
  @applicable_hosts
end

#applicable_tasksObject (readonly)

Returns the value of attribute applicable_tasks.



6
7
8
# File 'lib/tomo/runtime/host_execution_step.rb', line 6

def applicable_tasks
  @applicable_tasks
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/tomo/runtime/host_execution_step.rb', line 17

def empty?
  applicable_tasks.empty?
end

#execute(thread_pool:, remotes:) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/tomo/runtime/host_execution_step.rb', line 21

def execute(thread_pool:, remotes:)
  return if applicable_tasks.empty?

  thread_pool.post do
    applicable_tasks.each do |task|
      break if thread_pool.failure?

      task_host = task.is_a?(PrivilegedTask) ? host.as_privileged : host
      remote = remotes[task_host]
      task_runner.run(task:, remote:)
    end
  end
end

#explainObject



35
36
37
38
39
40
41
42
# File 'lib/tomo/runtime/host_execution_step.rb', line 35

def explain
  desc = []
  applicable_tasks.each do |task|
    task_host = task.is_a?(PrivilegedTask) ? host.as_privileged : host
    desc << "RUN #{task} ON #{task_host}"
  end
  desc.join("\n")
end