added threading and ability to specify environment for remote tasks
This commit is contained in:
parent
c281a82151
commit
b8cff6023a
@ -88,7 +88,6 @@ module Hydra #:nodoc:
|
|||||||
Sync.new worker_opts, @sync, @verbose
|
Sync.new worker_opts, @sync, @verbose
|
||||||
rescue
|
rescue
|
||||||
trace "Syncing failed [#{worker_opts.inspect}]"
|
trace "Syncing failed [#{worker_opts.inspect}]"
|
||||||
Thread.exit
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -165,33 +165,60 @@ module Hydra #:nodoc:
|
|||||||
desc "Run #{@name} remotely on all workers"
|
desc "Run #{@name} remotely on all workers"
|
||||||
task "hydra:remote:#{@name}" do
|
task "hydra:remote:#{@name}" do
|
||||||
config = YAML.load_file(@config)
|
config = YAML.load_file(@config)
|
||||||
|
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'}
|
||||||
|
|
||||||
|
$stdout.write "==== Hydra Running #{@name} ====\n"
|
||||||
|
Thread.abort_on_exception = true
|
||||||
|
@listeners = []
|
||||||
|
@results = {}
|
||||||
workers.each do |worker|
|
workers.each do |worker|
|
||||||
$stdout.write "==== Hydra Running #{@name} on #{worker['connect']} ====\n"
|
@listeners << Thread.new do
|
||||||
ssh_opts = worker.fetch('ssh_opts') { '' }
|
begin
|
||||||
writer, reader, error = popen3("ssh -tt #{ssh_opts} #{worker['connect']} ")
|
@results[worker] = if run_task(worker, environment)
|
||||||
writer.write("cd #{worker['directory']}\n")
|
"==== #{@name} passed on #{worker['connect']} ====\n"
|
||||||
writer.write "echo BEGIN HYDRA\n"
|
else
|
||||||
writer.write("RAILS_ENV=test rake #{@name}\n")
|
"==== #{@name} failed on #{worker['connect']} ====\nPlease see above for more details.\n"
|
||||||
writer.write "echo END HYDRA\n"
|
end
|
||||||
writer.write("exit\n")
|
rescue
|
||||||
writer.close
|
@results[worker] = "==== #{@name} failed for #{worker['connect']} ====\n#{$!.inspect}\n#{$!.backtrace.join("\n")}"
|
||||||
ignoring = true
|
end
|
||||||
while line = reader.gets
|
end
|
||||||
line.chomp!
|
|
||||||
if line =~ /echo END HYDRA$/
|
|
||||||
ignoring = true
|
|
||||||
end
|
|
||||||
$stdout.write "#{line}\n" unless ignoring
|
|
||||||
if line == 'BEGIN HYDRA'
|
|
||||||
ignoring = false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
$stdout.write "\n==== Hydra Running #{@name} COMPLETE ====\n\n"
|
|
||||||
end
|
end
|
||||||
|
@listeners.each{|l| l.join}
|
||||||
|
$stdout.write "\n==== Hydra Running #{@name} COMPLETE ====\n\n"
|
||||||
|
$stdout.write @results.values.join('\n')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def run_task worker, environment
|
||||||
|
$stdout.write "==== Hydra Running #{@name} on #{worker['connect']} ====\n"
|
||||||
|
ssh_opts = worker.fetch('ssh_opts') { '' }
|
||||||
|
writer, reader, error = popen3("ssh -tt #{ssh_opts} #{worker['connect']} ")
|
||||||
|
writer.write("cd #{worker['directory']}\n")
|
||||||
|
writer.write "echo BEGIN HYDRA\n"
|
||||||
|
writer.write("RAILS_ENV=#{environment} rake #{@name}\n")
|
||||||
|
writer.write "echo END HYDRA\n"
|
||||||
|
writer.write("exit\n")
|
||||||
|
writer.close
|
||||||
|
ignoring = true
|
||||||
|
passed = true
|
||||||
|
while line = reader.gets
|
||||||
|
line.chomp!
|
||||||
|
if line =~ /^rake aborted!$/
|
||||||
|
passed = false
|
||||||
|
end
|
||||||
|
if line =~ /echo END HYDRA$/
|
||||||
|
ignoring = true
|
||||||
|
end
|
||||||
|
$stdout.write "#{worker['connect']}: #{line}\n" unless ignoring
|
||||||
|
if line == 'BEGIN HYDRA'
|
||||||
|
ignoring = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
passed
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# A Hydra global task is a task that is run both locally and remotely.
|
# A Hydra global task is a task that is run both locally and remotely.
|
||||||
|
Loading…
Reference in New Issue
Block a user