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 |
# 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
83 84 85 86 87 88 89 |
# File 'lib/acpc_table_manager/table_queue.rb', line 83 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
73 74 75 76 77 |
# File 'lib/acpc_table_manager/table_queue.rb', line 73 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
91 92 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 121 122 123 124 125 126 127 128 129 |
# File 'lib/acpc_table_manager/table_queue.rb', line 91 def check! return if length < 1 my_matches_to_start = matches_to_start.to_a max_running_matches = AcpcTableManager.exhibition_config.games[@game_definition_key]['max_num_matches'] check_num_running_matches = max_running_matches > 0 num_running_matches = 0 if check_num_running_matches num_running_matches = Match.running(my_matches).length log( __method__, num_running_matches: num_running_matches, num_matches_to_start: my_matches_to_start.length ) end matches_started = [] while !my_matches_to_start.empty? && ( !check_num_running_matches || num_running_matches < max_running_matches ) matches_started << dequeue(my_matches_to_start.pop) num_running_matches += 1 end log( __method__, matches_started: matches_started, num_running_matches: num_running_matches, num_matches_to_start: matches_to_start.length ) matches_started end |
#length ⇒ Object
79 80 81 |
# File 'lib/acpc_table_manager/table_queue.rb', line 79 def length matches_to_start.length end |
#matches_to_start ⇒ Object
65 66 67 |
# File 'lib/acpc_table_manager/table_queue.rb', line 65 def matches_to_start my_matches.queue end |
#my_matches ⇒ Object
69 70 71 |
# File 'lib/acpc_table_manager/table_queue.rb', line 69 def my_matches Match.where(game_definition_key: @game_definition_key.to_sym) end |
#start_players!(match) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/acpc_table_manager/table_queue.rb', line 35 def start_players!(match) Opponents.start(match) log(__method__, msg: "Opponents started for #{match.id}") start_proxy! match end |
#start_proxy!(match) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/acpc_table_manager/table_queue.rb', line 42 def start_proxy!(match) command = "#{File.('../../../exe/acpc_proxy', __FILE__)} -t #{AcpcTableManager.config_file} -m #{match.id}" log( __method__, msg: "Starting proxy for #{match.id}", 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})", pid: match.proxy_pid ) self end |