Sha256: a5d065ba2c23036aa52578943cc72fafa56e3d610db69c84fffa7207e39d1925

Contents?: true

Size: 1.82 KB

Versions: 19

Compression:

Stored size: 1.82 KB

Contents

#!/usr/bin/env ruby

require 'acpc_table_manager'
require 'redis'
require 'json'
require 'optparse'
require 'acpc_table_manager/match'


ARGV << '-h' if ARGV.empty?

options = {}
OptionParser.new do |opts|
  opts.banner = "Usage: #{$0} [options]"

  opts.on_tail("-h", "--help", "Show this message") do
    puts opts
    exit
  end

  opts.on("-t", "--table_manager TABLE MANAGER CONFIG", "Table manager configuration file.") do |c|
    options[:table_manager_config] = File.expand_path c, Dir.pwd
  end
end.parse!

raise OptionParser::MissingArgument.new('TABLE MANAGER CONFIG') unless options[:table_manager_config]

raise OptionParser::ArgumentError.new("#{options[:table_manager_config]} doesn't exist.") unless File.exist?(options[:table_manager_config])

CONFIG_FILE = options[:table_manager_config]

AcpcTableManager.load! CONFIG_FILE
table_manager = AcpcTableManager::Maintainer.new

Signal.trap("INT") { exit }
Signal.trap("TERM") { exit }

loop do
  begin
    message = AcpcTableManager.redis.blpop("table-manager", :timeout => AcpcTableManager.config.maintenance_interval_s)
    if message
      data = JSON.parse message[1]
      table_manager.log(__method__, {data: data})

      case data['request']
      when AcpcTableManager.config.check_matches
      when AcpcTableManager.config.kill_match
        match = AcpcTableManager::Match.quiet_find data['params'][AcpcTableManager.config.match_id_key]
        if match then match.kill_proxy! end
      when 'reload'
        AcpcTableManager.load! CONFIG_FILE
      else
        raise StandardError.new("Unrecognized request: #{data['request']}")
      end
    end
    table_manager.maintain!
  rescue => e
    table_manager.log(
      __method__,
      {
        message: e.message,
        backtrace: e.backtrace
      },
      Logger::Severity::ERROR
    )
    AcpcTableManager.notify e
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
acpc_table_manager-3.0.18 exe/acpc_table_manager
acpc_table_manager-3.0.17 exe/acpc_table_manager
acpc_table_manager-3.0.16 exe/acpc_table_manager
acpc_table_manager-3.0.15 exe/acpc_table_manager
acpc_table_manager-3.0.14 exe/acpc_table_manager
acpc_table_manager-3.0.13 exe/acpc_table_manager
acpc_table_manager-3.0.12 exe/acpc_table_manager
acpc_table_manager-3.0.11 exe/acpc_table_manager
acpc_table_manager-3.0.10 exe/acpc_table_manager
acpc_table_manager-3.0.9 exe/acpc_table_manager
acpc_table_manager-3.0.8 exe/acpc_table_manager
acpc_table_manager-3.0.7 exe/acpc_table_manager
acpc_table_manager-3.0.6 exe/acpc_table_manager
acpc_table_manager-3.0.5 exe/acpc_table_manager
acpc_table_manager-3.0.4 exe/acpc_table_manager
acpc_table_manager-3.0.3 exe/acpc_table_manager
acpc_table_manager-3.0.2 exe/acpc_table_manager
acpc_table_manager-3.0.1 exe/acpc_table_manager
acpc_table_manager-3.0.0 exe/acpc_table_manager