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 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 }
|
||||
else
|
||||
false
|
||||
|
@ -11,7 +11,10 @@ module Hydra #:nodoc:
|
||||
while true
|
||||
begin
|
||||
raise IOError unless @reader
|
||||
message = @reader.gets
|
||||
if !@timeout || (result = Kernel.select([@reader], [], [], @timeout))
|
||||
message = @reader.gets
|
||||
end
|
||||
return Message.build(:class => Hydra::Messages::Master::Shutdown) if result == nil
|
||||
return nil unless message
|
||||
return Message.build(eval(message.chomp))
|
||||
rescue SyntaxError, NameError
|
||||
|
@ -31,9 +31,10 @@ module Hydra #:nodoc:
|
||||
class Pipe
|
||||
include Hydra::MessagingIO
|
||||
# Creates a new uninitialized pipe pair.
|
||||
def initialize
|
||||
def initialize(timeout = nil)
|
||||
@child_read, @parent_write = IO.pipe
|
||||
@parent_read, @child_write = IO.pipe
|
||||
@timeout = timeout
|
||||
end
|
||||
|
||||
# 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')
|
||||
# To connect to server.com as user on port 3022, then CD to their desktop, then
|
||||
# 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}'})
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user