even better timeout handling for ssh pipes
This commit is contained in:
parent
16809a69dc
commit
5ef29ee43e
|
@ -172,7 +172,7 @@ module Hydra #:nodoc:
|
||||||
|
|
||||||
trace "Booting SSH worker"
|
trace "Booting SSH worker"
|
||||||
trace command
|
trace command
|
||||||
ssh = Hydra::SSH.new("#{sync.ssh_opts} #{sync.connect}", sync.remote_dir, command)
|
ssh = Hydra::SSH.new("#{sync.ssh_opts} #{sync.connect}", sync.remote_dir, command, worker['timeout'])
|
||||||
return { :io => ssh, :idle => false, :type => :ssh, :connect => sync.connect }
|
return { :io => ssh, :idle => false, :type => :ssh, :connect => sync.connect }
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
|
|
|
@ -11,7 +11,10 @@ module Hydra #:nodoc:
|
||||||
while true
|
while true
|
||||||
begin
|
begin
|
||||||
raise IOError unless @reader
|
raise IOError unless @reader
|
||||||
|
if !@timeout || (result = Kernel.select([@reader], [], [], @timeout))
|
||||||
message = @reader.gets
|
message = @reader.gets
|
||||||
|
end
|
||||||
|
return Message.build(:class => Hydra::Messages::Master::Shutdown) if result == nil
|
||||||
return nil unless message
|
return nil unless message
|
||||||
return Message.build(eval(message.chomp))
|
return Message.build(eval(message.chomp))
|
||||||
rescue SyntaxError, NameError
|
rescue SyntaxError, NameError
|
||||||
|
|
|
@ -31,9 +31,10 @@ module Hydra #:nodoc:
|
||||||
class Pipe
|
class Pipe
|
||||||
include Hydra::MessagingIO
|
include Hydra::MessagingIO
|
||||||
# Creates a new uninitialized pipe pair.
|
# Creates a new uninitialized pipe pair.
|
||||||
def initialize
|
def initialize(timeout = nil)
|
||||||
@child_read, @parent_write = IO.pipe
|
@child_read, @parent_write = IO.pipe
|
||||||
@parent_read, @child_write = IO.pipe
|
@parent_read, @child_write = IO.pipe
|
||||||
|
@timeout = timeout
|
||||||
end
|
end
|
||||||
|
|
||||||
# Identify this side of the pipe as the child.
|
# Identify this side of the pipe as the child.
|
||||||
|
|
|
@ -25,7 +25,8 @@ module Hydra #:nodoc:
|
||||||
# Hydra::SSH.new('-p 3022 user@server.com', '/home/user/Desktop', 'ls -l')
|
# Hydra::SSH.new('-p 3022 user@server.com', '/home/user/Desktop', 'ls -l')
|
||||||
# To connect to server.com as user on port 3022, then CD to their desktop, then
|
# To connect to server.com as user on port 3022, then CD to their desktop, then
|
||||||
# list all the files.
|
# list all the files.
|
||||||
def initialize(connection_options, directory, command)
|
def initialize(connection_options, directory, command, timeout = nil)
|
||||||
|
@timeout = timeout
|
||||||
@writer, @reader, @error = popen3(%{ssh -tt #{connection_options} 'mkdir -p #{directory} && cd #{directory} && #{command}'})
|
@writer, @reader, @error = popen3(%{ssh -tt #{connection_options} 'mkdir -p #{directory} && cd #{directory} && #{command}'})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue