acpc_table_manager 3.0.11 → 3.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6045e649f8474fe093e827a3fd6c659aa639a26
4
- data.tar.gz: c19ca84bbb26ce0285dbcb6d7a2bae23dda3c341
3
+ metadata.gz: f0e45bdd8fff4488222915a4e977067542d335c4
4
+ data.tar.gz: '0992f61ada4f67006c53c1653ef371f1d11f6950'
5
5
  SHA512:
6
- metadata.gz: e58888e75fd4f7918cd41a3ad5cb23be6406d05a28e52a38fed941552e8f8ff68519008bdadf84f8fe1a53d3dcbb99cd2d463bf3e1d08d62c811f3a1649303cb
7
- data.tar.gz: 0356b56a54da1ae702bacd23c575cc541c184f127db14ceb5a1ce2ba812ffcfe49f47900551c9e50909fffeb16dbf2627f9ae27a2604a981be7fedecdfed7b9d
6
+ metadata.gz: 654139f50b17ec5541c14b977049d47e67aae1caccc55c70297938cae5828eb344efd9d3c54e255242da02953b0047e74575c71b33bc03f5efc0dd6ae5fafd19
7
+ data.tar.gz: 3a2ad7ac571d4a9beba6bd6e020023e289f5dda4840e5e305a8bc4e795a1b55637c06c2022786c5856d22c4816db4c4839a7b6b83d3b3cb10888a88ba38fdf1c
@@ -113,7 +113,11 @@ class Match
113
113
  end
114
114
 
115
115
  def ports_in_use(matches=all)
116
- running(matches).inject([]) { |ports, m| ports += m.port_numbers }
116
+ ports = []
117
+ matches.possibly_running.each do |match|
118
+ ports += m.port_numbers if match.running?
119
+ end
120
+ ports
117
121
  end
118
122
 
119
123
  def kill_all_orphan_processes!(matches=all)
@@ -91,27 +91,30 @@ module AcpcTableManager
91
91
  end
92
92
 
93
93
  def check!
94
+ my_matches_to_start = matches_to_start.to_a
95
+ num_running_matches = Match.running(my_matches).length
94
96
  log(
95
97
  __method__,
96
98
  {
97
- num_running_matches: Match.running(my_matches).length,
98
- num_matches_to_start: matches_to_start.length
99
+ num_running_matches: num_running_matches,
100
+ num_matches_to_start: my_matches_to_start.length
99
101
  }
100
102
  )
101
103
 
102
104
  matches_started = []
103
105
  while (
104
- !matches_to_start.empty? &&
105
- Match.running(my_matches).length < AcpcTableManager.exhibition_config.games[@game_definition_key]['max_num_matches']
106
+ !my_matches_to_start.empty? &&
107
+ num_running_matches < AcpcTableManager.exhibition_config.games[@game_definition_key]['max_num_matches']
106
108
  )
107
- matches_started << dequeue
109
+ matches_started << dequeue(my_matches_to_start.pop)
110
+ num_running_matches += 1
108
111
  end
109
112
 
110
113
  log(
111
114
  __method__,
112
115
  {
113
116
  matches_started: matches_started,
114
- num_running_matches: Match.running(my_matches).length,
117
+ num_running_matches: num_running_matches,
115
118
  num_matches_to_start: matches_to_start.length
116
119
  }
117
120
  )
@@ -121,13 +124,13 @@ module AcpcTableManager
121
124
 
122
125
  protected
123
126
 
124
- def port(available_ports_)
125
- port_ = available_ports_.pop
127
+ def port(available_ports)
128
+ port_ = available_ports.pop
126
129
  while !AcpcDealer::port_available?(port_)
127
- if available_ports_.empty?
130
+ if available_ports.empty?
128
131
  raise NoPortForDealerAvailable.new("None of the special ports (#{available_special_ports}) are open")
129
132
  end
130
- port_ = available_ports_.pop
133
+ port_ = available_ports.pop
131
134
  end
132
135
  unless port_
133
136
  raise NoPortForDealerAvailable.new("None of the special ports (#{available_special_ports}) are open")
@@ -135,18 +138,22 @@ module AcpcTableManager
135
138
  port_
136
139
  end
137
140
 
141
+ def ports_to_use(special_port_requirements, available_ports = nil)
142
+ ports = special_port_requirements.map do |r|
143
+ if r
144
+ # Slow. Only check available special ports if necessary
145
+ available_ports ||= available_special_ports
146
+ port(available_ports)
147
+ else
148
+ 0
149
+ end
150
+ end
151
+ return ports, available_ports
152
+ end
153
+
138
154
  # @return [Object] The match that has been started or +nil+ if none could
139
155
  # be started.
140
- def dequeue
141
- my_matches_to_start = matches_to_start
142
- log(
143
- __method__,
144
- num_matches_to_start: my_matches_to_start.length
145
- )
146
- return nil if my_matches_to_start.empty?
147
-
148
- match = my_matches_to_start.last
149
-
156
+ def dequeue(match)
150
157
  log(
151
158
  __method__,
152
159
  msg: "Starting dealer for match \"#{match.name}\" (#{match.id})",
@@ -158,10 +165,7 @@ module AcpcTableManager
158
165
  # Add user's port
159
166
  special_port_requirements.insert(match.seat - 1, false)
160
167
 
161
- available_ports_ = available_special_ports
162
- ports_to_be_used = special_port_requirements.map do |r|
163
- if r then port(available_ports_) else 0 end
164
- end
168
+ ports_to_be_used, available_ports = ports_to_use(special_port_requirements)
165
169
 
166
170
  num_repetitions = 0
167
171
  dealer_info = nil
@@ -170,7 +174,7 @@ module AcpcTableManager
170
174
  log(
171
175
  __method__,
172
176
  msg: "Added #{match.id} list of running matches",
173
- available_special_ports: available_ports_,
177
+ available_special_ports: available_ports,
174
178
  special_port_requirements: special_port_requirements,
175
179
  :'ports_to_be_used_(zero_for_random)' => ports_to_be_used
176
180
  )
@@ -183,14 +187,12 @@ module AcpcTableManager
183
187
  Logger::Severity::WARN
184
188
  )
185
189
  begin
186
- ports_to_be_used = special_port_requirements.map do |r|
187
- if r then port(available_ports_) else 0 end
188
- end
190
+ ports_to_be_used, available_ports = ports_to_use(special_port_requirements, available_ports)
189
191
  rescue NoPortForDealerAvailable => e
190
- available_ports_ = available_special_ports
192
+ available_ports = available_special_ports
191
193
  log(
192
194
  __method__,
193
- {warning: "#{ports_to_be_used} ports unavailable, retrying with all special ports, #{available_ports_}."},
195
+ {warning: "#{ports_to_be_used} ports unavailable, retrying with all special ports, #{available_ports}."},
194
196
  Logger::Severity::WARN
195
197
  )
196
198
  end
@@ -198,7 +200,7 @@ module AcpcTableManager
198
200
  sleep 1
199
201
  log(
200
202
  __method__,
201
- {warning: "Retrying with all special ports, #{available_ports_}."},
203
+ {warning: "Retrying with all special ports, #{available_ports}."},
202
204
  Logger::Severity::WARN
203
205
  )
204
206
  num_repetitions += 1
@@ -1,3 +1,3 @@
1
1
  module AcpcTableManager
2
- VERSION = "3.0.11"
2
+ VERSION = "3.0.12"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acpc_table_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.11
4
+ version: 3.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Morrill