]> Entropealabs - wampex_router.git/commitdiff
handle callee index somehow getting turned into multiple items in list
authorChristopher <chris@entropealabs.com>
Thu, 16 Apr 2020 16:37:40 +0000 (11:37 -0500)
committerChristopher <chris@entropealabs.com>
Thu, 16 Apr 2020 16:37:40 +0000 (11:37 -0500)
lib/router/realms/session.ex

index f2ecda0a16e15c66645b2d05204b6ccebfb971b2..22636bf8043b44be329f4cf60fe66d93e9e8db16 100644 (file)
@@ -25,12 +25,26 @@ defmodule Wampex.Router.Realms.Session do
 
       {_key, callees} ->
         Logger.info("Got Callees: #{inspect(callees)}")
-        {_key, [callee_index]} = ClusterKV.get(db, realm, "#{procedure}:callee_index")
+        callee_index = get_index(db, realm, procedure)
         Logger.info("Got Index: #{callee_index}")
         {callees, callee_index}
     end
   end
 
+  def get_index(db, realm, proc) do
+    case ClusterKV.get(db, realm, "#{proc}:callee_index") do
+      {_key, [callee_index]} ->
+        callee_index
+
+      {_key, [_ | t]} ->
+        Logger.info("Got list of indexes... #{inspect(t)}")
+        get_last_index(t)
+    end
+  end
+
+  def get_last_index([i]), do: i
+  def get_last_index([_ | t]), do: get_last_index(t)
+
   def round_robin(db, realm, procedure, len) do
     ClusterKV.update(db, realm, "#{procedure}:callee_index", len, &update_round_robin/2)
   end