Setup a task that will be run across all remote workers
Hydra::RemoteTask.new('db:reset')
Then you can run:
rake hydra:remote:db:reset
Create a new hydra remote task with the given name. The task will be named hydra:remote:<name>
# File lib/hydra/tasks.rb, line 269 def initialize(name, command=nil) @name = name @command = command yield self if block_given? @config = find_config_file if @config define else task "hydra:remote:#{@name}" do ; end end end
# File lib/hydra/tasks.rb, line 282 def define desc "Run #{@name} remotely on all workers" task "hydra:remote:#{@name}" do config = YAML.load_file(@config) environment = config.fetch('environment') { 'test' } workers = config.fetch('workers') { [] } workers = workers.select{|w| w['type'] == 'ssh'} @command = "RAILS_ENV=#{environment} rake #{@name}" unless @command $stdout.write "==== Hydra Running #{@name} ====\n" Thread.abort_on_exception = true @listeners = [] @results = {} workers.each do |worker| @listeners << Thread.new do begin @results[worker] = if run_command(worker, @command) "==== #{@name} passed on #{worker['connect']} ====\n" else "==== #{@name} failed on #{worker['connect']} ====\nPlease see above for more details.\n" end rescue @results[worker] = "==== #{@name} failed for #{worker['connect']} ====\n#{$!.inspect}\n#{$!.backtrace.join("\n")}" end end end @listeners.each{|l| l.join} $stdout.write "\n==== Hydra Running #{@name} COMPLETE ====\n\n" $stdout.write @results.values.join("\n") end end
# File lib/hydra/tasks.rb, line 314 def run_command worker, command $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(command + "\r") 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