Sha256: 0a882fe432e29228c0cd30d41042493eee2f78461c80b860afa5e80a4b54abe7

Contents?: true

Size: 1.07 KB

Versions: 4

Compression:

Stored size: 1.07 KB

Contents

module RProxy
  class ProcessHandler < EventMachine::ProcessWatch

    def initialize(pids, config, socket, pid)
      @pids = pids
      @id = pid
      @config = config
      @socket = socket
      @logger = config.logger
    end

    def process_exited

      @pids.delete(@id)
      timestamp = Time.now.to_i

      pid = Process.fork do
        begin
          @logger.info("r_proxy rebuild new instance replace @#{timestamp}....") if @logger
          RProxy::ProxyServer.new(@socket, @config).run!
        rescue Interrupt
          @logger.info("r_proxy TPC server instance @#{timestamp} closed now....") if @logger
        rescue => e
          @logger.error("instance @#{timestamp}, error: #{e.message}, #{e.backtrace}") if @logger
          exit(false)
        end
      end

      Process.detach(pid)
      @pids << pid

      EventMachine.watch_process(pid, RProxy::ProcessHandler,
                                 @pids,
                                 @config,
                                 @socket,
                                 pid)
      close_connection
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
r_proxy-0.2.1 lib/r_proxy/process_handler.rb
r_proxy-0.2.0 lib/r_proxy/process_handler.rb
r_proxy-0.1.1 lib/r_proxy/process_handler.rb
r_proxy-0.1.0 lib/r_proxy/process_handler.rb