Skip to content

Commit 4a20ae0

Browse files
committed
initial implementation of support for comma-separated tag list
1 parent f8680b9 commit 4a20ae0

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

app/models/server.rb

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -286,24 +286,36 @@ def self.find(id)
286286
end
287287

288288
# Find the server with the lowest load (for creating a new meeting)
289-
def self.find_available(tag_arg = nil)
290-
# Check if tag is required
291-
tag = tag_arg.presence
292-
tag_required = false
293-
if !tag.nil? && tag[-1] == '!'
294-
tag = tag[0..-2].presence # always returns String, if tag is String
295-
tag_required = true
289+
def self.find_available(tags_arg = nil)
290+
# Check if passed tags are required
291+
tags_arg = tags_arg.presence
292+
tags_required = false
293+
if !tags_arg.nil? && tags_arg[-1] == '!'
294+
tags_arg = tags_arg[0..-2].presence # always returns String, if tag is String
295+
tags_required = true
296296
end
297+
tags = tags_arg&.split(',')
297298

298299
# Find available&matching server with the lowest load
299300
with_connection do |redis|
300301
ids_loads = redis.zrange('server_load', 0, -1, with_scores: true)
301302
raise RecordNotFound.new("Could not find any available servers.", name, nil) if ids_loads.blank?
302-
if !tag.nil? && ids_loads.none? { |myid, _| redis.hget(key(myid), 'tag') == tag }
303-
raise BBBErrors::ServerTagUnavailableError, tag if tag_required
304-
tag = nil # fall back to servers without tag
303+
304+
# build a list of matching tagged servers, otherwise fall back to untagged
305+
if !tags.nil?
306+
ids_loads_tagged = []
307+
tags.each do |tag|
308+
ids_loads_tagged.concat ids_loads.select { |myid, _| redis.hget(key(myid), 'tag') == tag }
309+
end
310+
if ids_loads_tagged.blank?
311+
raise BBBErrors::ServerTagUnavailableError, tags_arg if tags_required
312+
tags = nil # fall back to servers without tag
313+
ids_loads_tagged = ids_loads.select { |myid, _| redis.hget(key(myid), 'tag') == nil }
314+
end
315+
ids_loads = ids_loads_tagged
305316
end
306-
ids_loads = ids_loads.select { |myid, _| redis.hget(key(myid), 'tag') == tag }
317+
318+
# try to select the server with lowest load
307319
id, load, hash = ids_loads.each do |id, load|
308320
hash = redis.hgetall(key(id))
309321
break id, load, hash if hash.present?

0 commit comments

Comments
 (0)