Class: Rake::RemoteTask::Action
- Inherits:
-
Object
- Object
- Rake::RemoteTask::Action
- 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
-
#block ⇒ Object
readonly
The block this action will execute.
-
#task ⇒ Object
readonly
The task this action is attached to.
-
#workers ⇒ Object
readonly
An Array of threads, one for each host this action executes on.
Instance Method Summary collapse
-
#==(other) ⇒ Object
:nodoc:.
-
#execute(hosts, task, args) ⇒ Object
Execute this action on
hosts
in parallel. -
#initialize(task, block) ⇒ Action
constructor
Creates a new Action that will run
block
fortask
.
Constructor Details
#initialize(task, block) ⇒ Action
Creates a new Action that will run block
for task
.
607 608 609 610 611 |
# File 'lib/rake/remote_task.rb', line 607 def initialize task, block @task = task @block = block @workers = ThreadGroup.new end |
Instance Attribute Details
#block ⇒ Object (readonly)
The block this action will execute.
597 598 599 |
# File 'lib/rake/remote_task.rb', line 597 def block @block end |
#task ⇒ Object (readonly)
The task this action is attached to.
592 593 594 |
# File 'lib/rake/remote_task.rb', line 592 def task @task end |
#workers ⇒ Object (readonly)
An Array of threads, one for each host this action executes on.
602 603 604 |
# File 'lib/rake/remote_task.rb', line 602 def workers @workers end |
Instance Method Details
#==(other) ⇒ Object
:nodoc:
613 614 615 616 |
# File 'lib/rake/remote_task.rb', line 613 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.
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 |
# File 'lib/rake/remote_task.rb', line 622 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 |