Class: Kdeploy::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/kdeploy/runner.rb

Overview

Concurrent task runner for executing tasks across multiple hosts

Instance Method Summary collapse

Constructor Details

#initialize(hosts, tasks, parallel: Configuration.default_parallel, output: ConsoleOutput.new) ⇒ Runner

Returns a new instance of Runner.



8
9
10
11
12
13
14
15
# File 'lib/kdeploy/runner.rb', line 8

def initialize(hosts, tasks, parallel: Configuration.default_parallel, output: ConsoleOutput.new)
  @hosts = hosts
  @tasks = tasks
  @parallel = parallel
  @output = output
  @pool = Concurrent::FixedThreadPool.new(@parallel)
  @results = Concurrent::Hash.new
end

Instance Method Details

#run(task_name) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/kdeploy/runner.rb', line 17

def run(task_name)
  task = @tasks[task_name]
  raise TaskNotFoundError, task_name unless task

  futures = @hosts.map do |name, config|
    Concurrent::Future.execute(executor: @pool) do
      execute_task_for_host(name, config, task)
    end
  end

  futures.each(&:wait)
  @results
ensure
  @pool.shutdown
end