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, args = nil) ⇒ 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
.
536 537 538 539 540 |
# File 'lib/rake_remote_task.rb', line 536 def initialize task, block @task = task @block = block @workers = [] end |
Instance Attribute Details
#block ⇒ Object (readonly)
The block this action will execute.
526 527 528 |
# File 'lib/rake_remote_task.rb', line 526 def block @block end |
#task ⇒ Object (readonly)
The task this action is attached to.
521 522 523 |
# File 'lib/rake_remote_task.rb', line 521 def task @task end |
#workers ⇒ Object (readonly)
An Array of threads, one for each host this action executes on.
531 532 533 |
# File 'lib/rake_remote_task.rb', line 531 def workers @workers end |
Instance Method Details
#==(other) ⇒ Object
:nodoc:
542 543 544 545 |
# File 'lib/rake_remote_task.rb', line 542 def == other # :nodoc: return false unless Action === other block == other.block && task == other.task end |
#execute(hosts, args = nil) ⇒ Object
Execute this action on hosts
in parallel. Returns when block has completed for each host.
551 552 553 554 555 556 557 558 559 560 561 562 |
# File 'lib/rake_remote_task.rb', line 551 def execute hosts, args = nil hosts.each do |host| t = task.clone t.target_host = host thread = Thread.new(t) do |task| Thread.current[:task] = task block.call args end @workers << thread end @workers.each { |w| w.join } end |