Sha256: 2afc3a89a06dfd44e9dc241a1503ccc10c06b33466747c5937f035ed275af867
Contents?: true
Size: 1.43 KB
Versions: 6
Compression:
Stored size: 1.43 KB
Contents
# encoding: utf-8 # This file is distributed under New Relic's license terms. # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details. require 'socket' module FlakyProxy class Proxy def initialize(options) @listen_host = options.fetch(:listen_host) @listen_port = options.fetch(:listen_port) @backend_server = Server.new(options.fetch(:target_host), options.fetch(:target_port)) @rules = RuleSet.build('') @rules_path = options[:rules_path] @listen_socket = nil end def reload_rules_file if @rules_path mtime = File.stat(@rules_path).mtime if @last_rules_mtime.nil? || mtime > @last_rules_mtime FlakyProxy.logger.info("Reloading rules file at #{@rules_path}") @rules = RuleSet.build(File.read(@rules_path)) @last_rules_mtime = mtime end end end def run FlakyProxy.logger.info("Starting FlakyProxy on #{@listen_host}:#{@listen_port} -> #{@backend_server.to_s}") @listen_socket = TCPServer.new(@listen_host, @listen_port) loop do client_socket = @listen_socket.accept reload_rules_file FlakyProxy.logger.info("Accepted connection from #{client_socket}") connection = Connection.new(client_socket, @backend_server, @rules) connection.service FlakyProxy.logger.info("Finished servicing connection from #{client_socket}") end end end end
Version data entries
6 entries across 6 versions & 1 rubygems