Class: Tomo::Runtime::HostExecutionStep
- Inherits:
-
Object
- Object
- Tomo::Runtime::HostExecutionStep
- Defined in:
- lib/tomo/runtime/host_execution_step.rb
Instance Attribute Summary collapse
-
#applicable_hosts ⇒ Object
readonly
Returns the value of attribute applicable_hosts.
-
#applicable_tasks ⇒ Object
readonly
Returns the value of attribute applicable_tasks.
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #execute(thread_pool:, remotes:) ⇒ Object
- #explain ⇒ Object
-
#initialize(tasks:, host:, task_filter:, task_runner:) ⇒ HostExecutionStep
constructor
A new instance of HostExecutionStep.
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_hosts ⇒ Object (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_tasks ⇒ Object (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
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 |
#explain ⇒ Object
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 |