class Rake::RemoteTask::Action

Action is used to run a task's remote_actions in parallel on each of its hosts. Actions are created automatically in Rake::RemoteTask#enhance.

Attributes

block[R]

The block this action will execute.

task[R]

The task this action is attached to.

workers[R]

An Array of threads, one for each host this action executes on.

Public Class Methods

new(task, block) click to toggle source

Creates a new Action that will run block for task.

# File lib/rake/remote_task.rb, line 672
def initialize task, block
  @task  = task
  @block = block
  @workers = ThreadGroup.new
end

Public Instance Methods

execute(hosts, task, args) click to toggle source

Execute this action on hosts in parallel. Returns when block has completed for each host.

# File lib/rake/remote_task.rb, line 687
def execute hosts, task, args
  hosts.each do |host|
    t = task.clone
    t.target_host = host
    thread = Thread.new(t) do |task2|
      Thread.current[:task] = task2
      case block.arity
      when 1
        block.call task2
      else
        block.call task2, args
      end
      Thread.current[:task] = nil
    end
    @workers.add thread
  end
  @workers.list.each { |thr| thr.join }
end