Sha256: 70f21f94886030f8c0bfff0dbbc15e5879d3156339d03de074eef28ec29fb05b
Contents?: true
Size: 1.57 KB
Versions: 18
Compression:
Stored size: 1.57 KB
Contents
require 'timeout' require 'process_runner' require_relative 'config' require_relative 'simple_logging' require 'fileutils' module AcpcTableManager module Opponents extend SimpleLogging @logger = nil # @return [Array<Integer>] PIDs of the opponents started def self.start(match) @logger ||= ::AcpcTableManager.new_log 'opponents.log' opponents = match.bots(AcpcTableManager.config.dealer_host) log __method__, num_opponents: opponents.length if opponents.empty? raise StandardError.new("No opponents found to start for \"#{match.name}\" (#{match.id.to_s})!") end opponents_log_dir = File.join(AcpcTableManager.config.log_directory, 'opponents') FileUtils.mkdir(opponents_log_dir) unless File.directory?(opponents_log_dir) bot_start_commands = opponents.map do |name, info| { args: [info[:runner], info[:host], info[:port]], log: File.join(opponents_log_dir, "#{match.name}.#{match.id}.#{name}.log") } end bot_start_commands.map do |bot_start_command| log( __method__, { bot_start_command_parameters: bot_start_command[:args], command_to_be_run: bot_start_command[:args].join(' ') } ) pid = Timeout::timeout(3) do ProcessRunner.go( bot_start_command[:args].map { |e| e.to_s }, { [:err, :out] => [bot_start_command[:log], File::CREAT|File::WRONLY] } ) end log( __method__, { bot_started?: true, pid: pid } ) pid end end end end
Version data entries
18 entries across 18 versions & 1 rubygems