commit
0d1f0f5f9e
@ -243,8 +243,9 @@ module Hydra #:nodoc:
|
|||||||
include Open3
|
include Open3
|
||||||
# Create a new hydra remote task with the given name.
|
# Create a new hydra remote task with the given name.
|
||||||
# The task will be named hydra:remote:<name>
|
# The task will be named hydra:remote:<name>
|
||||||
def initialize(name)
|
def initialize(name, command=nil)
|
||||||
@name = name
|
@name = name
|
||||||
|
@command = command
|
||||||
yield self if block_given?
|
yield self if block_given?
|
||||||
@config = find_config_file
|
@config = find_config_file
|
||||||
if @config
|
if @config
|
||||||
@ -262,6 +263,7 @@ module Hydra #:nodoc:
|
|||||||
environment = config.fetch('environment') { 'test' }
|
environment = config.fetch('environment') { 'test' }
|
||||||
workers = config.fetch('workers') { [] }
|
workers = config.fetch('workers') { [] }
|
||||||
workers = workers.select{|w| w['type'] == 'ssh'}
|
workers = workers.select{|w| w['type'] == 'ssh'}
|
||||||
|
@command = "RAILS_ENV=#{environment} rake #{@name}" unless @command
|
||||||
|
|
||||||
$stdout.write "==== Hydra Running #{@name} ====\n"
|
$stdout.write "==== Hydra Running #{@name} ====\n"
|
||||||
Thread.abort_on_exception = true
|
Thread.abort_on_exception = true
|
||||||
@ -270,7 +272,7 @@ module Hydra #:nodoc:
|
|||||||
workers.each do |worker|
|
workers.each do |worker|
|
||||||
@listeners << Thread.new do
|
@listeners << Thread.new do
|
||||||
begin
|
begin
|
||||||
@results[worker] = if run_task(worker, environment)
|
@results[worker] = if run_command(worker, @command)
|
||||||
"==== #{@name} passed on #{worker['connect']} ====\n"
|
"==== #{@name} passed on #{worker['connect']} ====\n"
|
||||||
else
|
else
|
||||||
"==== #{@name} failed on #{worker['connect']} ====\nPlease see above for more details.\n"
|
"==== #{@name} failed on #{worker['connect']} ====\nPlease see above for more details.\n"
|
||||||
@ -286,13 +288,13 @@ module Hydra #:nodoc:
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_task worker, environment
|
def run_command worker, command
|
||||||
$stdout.write "==== Hydra Running #{@name} on #{worker['connect']} ====\n"
|
$stdout.write "==== Hydra Running #{@name} on #{worker['connect']} ====\n"
|
||||||
ssh_opts = worker.fetch('ssh_opts') { '' }
|
ssh_opts = worker.fetch('ssh_opts') { '' }
|
||||||
writer, reader, error = popen3("ssh -tt #{ssh_opts} #{worker['connect']} ")
|
writer, reader, error = popen3("ssh -tt #{ssh_opts} #{worker['connect']} ")
|
||||||
writer.write("cd #{worker['directory']}\n")
|
writer.write("cd #{worker['directory']}\n")
|
||||||
writer.write "echo BEGIN HYDRA\n"
|
writer.write "echo BEGIN HYDRA\n"
|
||||||
writer.write("RAILS_ENV=#{environment} rake #{@name}\n")
|
writer.write(command + "\r")
|
||||||
writer.write "echo END HYDRA\n"
|
writer.write "echo END HYDRA\n"
|
||||||
writer.write("exit\n")
|
writer.write("exit\n")
|
||||||
writer.close
|
writer.close
|
||||||
|
6
test/fixtures/task_test_config.yml
vendored
Normal file
6
test/fixtures/task_test_config.yml
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
workers:
|
||||||
|
- type: ssh
|
||||||
|
connect: localhost
|
||||||
|
directory: /tmp
|
||||||
|
runners: 1
|
21
test/task_test.rb
Normal file
21
test/task_test.rb
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
||||||
|
require 'hydra/tasks'
|
||||||
|
require 'rake'
|
||||||
|
|
||||||
|
class TaskTest < Test::Unit::TestCase
|
||||||
|
context "a task" do
|
||||||
|
should "execute the command in a remote machine" do
|
||||||
|
|
||||||
|
File.delete( "/tmp/new_file" ) if File.exists? "/tmp/new_file"
|
||||||
|
|
||||||
|
Hydra::RemoteTask.new('cat:text_file', 'touch new_file') do |t|
|
||||||
|
t.config = "test/fixtures/task_test_config.yml"
|
||||||
|
end
|
||||||
|
|
||||||
|
Rake.application['hydra:remote:cat:text_file'].invoke
|
||||||
|
|
||||||
|
assert( File.exists? "/tmp/new_file" )
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user