@@ -292,7 +292,7 @@ def self.find_available(tags_arg = nil)
292
292
tags_required = false
293
293
if !tags_arg . nil? && tags_arg [ -1 ] == '!'
294
294
tags_arg = tags_arg [ 0 ..-2 ] . presence # always returns String, if tag is String
295
- tags_required = true
295
+ tags_required = true unless tags_arg . nil?
296
296
end
297
297
tags = tags_arg &.split ( ',' )
298
298
@@ -307,14 +307,14 @@ def self.find_available(tags_arg = nil)
307
307
tags . each do |tag |
308
308
ids_loads_tagged . concat ids_loads . select { |myid , _ | redis . hget ( key ( myid ) , 'tag' ) == tag }
309
309
end
310
- ids_loads_tagged . sort_by { |id_load | id_load [ 1 ] }
311
- if ids_loads_tagged . blank?
312
- raise BBBErrors ::ServerTagUnavailableError , tags_arg if tags_required
313
- tags = nil # fall back to servers without tag
314
- ids_loads_tagged = ids_loads . select { |myid , _ | redis . hget ( key ( myid ) , 'tag' ) . nil? }
315
- end
316
- ids_loads = ids_loads_tagged
310
+ ids_loads_tagged . sort_by! { |id_load | id_load [ 1 ] }
311
+ end
312
+ if ids_loads_tagged . blank?
313
+ raise BBBErrors ::ServerTagUnavailableError , tags_arg if tags_required
314
+ tags = nil # fall back to servers without tag
315
+ ids_loads_tagged = ids_loads . select { |myid , _ | redis . hget ( key ( myid ) , 'tag' ) . nil? }
317
316
end
317
+ ids_loads = ids_loads_tagged
318
318
319
319
# try to select the server with lowest load
320
320
id , load , hash = ids_loads . each do |id , load |
0 commit comments