Class: AcpcTableManager::TableQueue
- Inherits:
-
Object
- Object
- AcpcTableManager::TableQueue
- Includes:
- SimpleLogging
- Defined in:
- lib/acpc_table_manager/table_queue.rb
Instance Attribute Summary collapse
-
#running_matches ⇒ Object
readonly
Returns the value of attribute running_matches.
Instance Method Summary collapse
- #available_special_ports ⇒ Object
- #change_in_number_of_running_matches? ⇒ Boolean
- #check! ⇒ Object
-
#initialize(game_definition_key_) ⇒ TableQueue
constructor
A new instance of TableQueue.
- #length ⇒ Object
- #matches_to_start ⇒ Object
- #my_matches ⇒ Object
- #start_players!(match) ⇒ Object
- #start_proxy!(match) ⇒ Object
Methods included from SimpleLogging
Constructor Details
#initialize(game_definition_key_) ⇒ TableQueue
Returns a new instance of TableQueue.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/acpc_table_manager/table_queue.rb', line 24 def initialize(game_definition_key_) @logger = AcpcTableManager.new_log 'queue.log' @game_definition_key = game_definition_key_ log( __method__, { game_definition_key: @game_definition_key, max_num_matches: AcpcTableManager.exhibition_config.games[@game_definition_key]['max_num_matches'] } ) end |
Instance Attribute Details
#running_matches ⇒ Object (readonly)
Returns the value of attribute running_matches.
20 21 22 |
# File 'lib/acpc_table_manager/table_queue.rb', line 20 def running_matches @running_matches end |
Instance Method Details
#available_special_ports ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/acpc_table_manager/table_queue.rb', line 85 def available_special_ports if AcpcTableManager.exhibition_config.special_ports_to_dealer AcpcTableManager.exhibition_config.special_ports_to_dealer - Match.ports_in_use else [] end end |
#change_in_number_of_running_matches? ⇒ Boolean
77 78 79 80 81 |
# File 'lib/acpc_table_manager/table_queue.rb', line 77 def change_in_number_of_running_matches? prevNumMatchesRunning = Match.running(my_matches).length yield if block_given? prevNumMatchesRunning != Match.running(my_matches).length end |
#check! ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/acpc_table_manager/table_queue.rb', line 93 def check! log( __method__, { num_running_matches: Match.running(my_matches).length, num_matches_to_start: matches_to_start.length } ) matches_started = [] while ( !matches_to_start.empty? && Match.running(my_matches).length < AcpcTableManager.exhibition_config.games[@game_definition_key]['max_num_matches'] ) matches_started << dequeue end log( __method__, { matches_started: matches_started, num_running_matches: Match.running(my_matches).length, num_matches_to_start: matches_to_start.length } ) matches_started end |
#length ⇒ Object
83 |
# File 'lib/acpc_table_manager/table_queue.rb', line 83 def length() matches_to_start.length end |
#matches_to_start ⇒ Object
71 |
# File 'lib/acpc_table_manager/table_queue.rb', line 71 def matches_to_start() my_matches.queue end |
#my_matches ⇒ Object
73 74 75 |
# File 'lib/acpc_table_manager/table_queue.rb', line 73 def my_matches Match.where(game_definition_key: @game_definition_key.to_sym) end |
#start_players!(match) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/acpc_table_manager/table_queue.rb', line 37 def start_players!(match) Opponents.start(match) log(__method__, msg: "Opponents started for #{match.id.to_s}") start_proxy! match end |
#start_proxy!(match) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/acpc_table_manager/table_queue.rb', line 44 def start_proxy!(match) command = "#{File.expand_path('../../../exe/acpc_proxy', __FILE__)} -t #{AcpcTableManager.config_file} -m #{match.id.to_s}" log( __method__, { msg: "Starting proxy for #{match.id.to_s}", command: command } ) match.proxy_pid = Timeout::timeout(3) do pid = Process.spawn(command) Process.detach(pid) pid end match.save! log( __method__, { msg: "Started proxy for \"#{match.name}\" (#{match.id.to_s})", pid: match.proxy_pid } ) self end |