Class: Rake::RemoteTask::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/rake/remote_task.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task, block) ⇒ Action

Creates a new Action that will run block for task.



672
673
674
675
676
# File 'lib/rake/remote_task.rb', line 672

def initialize task, block
  @task  = task
  @block = block
  @workers = ThreadGroup.new
end

Instance Attribute Details

#blockObject (readonly)

The block this action will execute.



662
663
664
# File 'lib/rake/remote_task.rb', line 662

def block
  @block
end

#taskObject (readonly)

The task this action is attached to.



657
658
659
# File 'lib/rake/remote_task.rb', line 657

def task
  @task
end

#workersObject (readonly)

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



667
668
669
# File 'lib/rake/remote_task.rb', line 667

def workers
  @workers
end

Instance Method Details

#==(other) ⇒ Object

:nodoc:



678
679
680
681
# File 'lib/rake/remote_task.rb', line 678

def == other # :nodoc:
  return false unless Action === other
  block == other.block && task == other.task
end

#execute(hosts, task, args) ⇒ Object

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



687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
# 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