Sha256: 63ee8c60a06c54642ccac5dd1f15b77f06ca925916272fde19d98525bf5b57db

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 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)
      pid = Process.fork do
        timestamp = (Time.now.to_f * 1000).round
        begin
          @logger.info("r_proxy rebuild new instance replace @#{timestamp}....") if @logger
          RProxy::ProxyServer.new(@socket, @config, timestamp).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

1 entries across 1 versions & 1 rubygems

Version Path
r_proxy-0.2.2 lib/r_proxy/process_handler.rb