Skip to content

Commit

Permalink
in server find_available, get server_load set only once and iterate t…
Browse files Browse the repository at this point in the history
…hrough it until server with valid hash is found (#1052)
  • Loading branch information
Ithanil authored Apr 5, 2024
1 parent e93f3f7 commit a659cb5
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions app/models/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,9 @@ def self.find(id)
# Find the server with the lowest load (for creating a new meeting)
def self.find_available
with_connection do |redis|
id, load, hash = 5.times do
ids_loads = redis.zrange('server_load', 0, 0, with_scores: true)
raise RecordNotFound.new("Couldn't find available Server", name, nil) if ids_loads.blank?

id, load = ids_loads.first
ids_loads = redis.zrange('server_load', 0, -1, with_scores: true)
raise RecordNotFound.new("Couldn't find available Server", name, nil) if ids_loads.blank?
id, load, hash = ids_loads.each do |id, load|
hash = redis.hgetall(key(id))
break id, load, hash if hash.present?
end
Expand Down

0 comments on commit a659cb5

Please sign in to comment.