class Bbq::Spawn::CoordinatedExecutor
Public Class Methods
new(executor, options = {})
click to toggle source
# File lib/bbq/spawn.rb, line 32 def initialize(executor, options = {}) @executor = executor @timeout = options.fetch(:timeout, 10) @banner = options[:banner] @host = options[:host] @port = options[:port] @url = options[:url] @reader, @writer = IO.pipe @strategy = options[:strategy] || IOStrategy::Squelch.new(@writer) end
Public Instance Methods
join()
click to toggle source
# File lib/bbq/spawn.rb, line 51 def join Timeout.timeout(@timeout) do wait_for_io if @banner wait_for_socket if @port and @host wait_for_response if @url end end
start()
click to toggle source
# File lib/bbq/spawn.rb, line 45 def start @strategy.run(@executor.io) @executor.start @strategy.after_run if @strategy.respond_to? :after_run end
Private Instance Methods
wait_for_io()
click to toggle source
# File lib/bbq/spawn.rb, line 60 def wait_for_io loop do output = @reader.readpartial(8192) break if output.include?(@banner) end rescue EOFError end
wait_for_response()
click to toggle source
# File lib/bbq/spawn.rb, line 79 def wait_for_response uri = URI.parse(@url) begin Net::HTTP.start(uri.host, uri.port) do |http| http.open_timeout = 5 http.read_timeout = 5 http.head(uri.path) end rescue SocketError, IOError, Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError retry end end
wait_for_socket()
click to toggle source
# File lib/bbq/spawn.rb, line 68 def wait_for_socket socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0) addr = Socket.pack_sockaddr_in(@port, @host) socket.connect(addr) rescue Errno::ECONNREFUSED retry ensure socket.close end