We need to have a list of valid peers and switch between them if the used one encounter issues.
I've tried a first solution for this problem :
# More for the idea than anything else. Currently it should work, but the
# Erlang beam crashed, telling the following message :
# eheap_alloc: Cannot allocate 915463784 bytes of memory (of type "heap").
def get_best_dev_peers do
peers = get_dev("api/peers")
peers["peers"]
|> Enum.map(fn (x) -> %{ip: x["ip"], delay: x["delay"]} end)
|> Enum.sort
|> Enum.slice(0, 10)
end
def get_random_viable_peer do
get_best_dev_peers()
|> Enum.random
end
def get_ip_from_random_peer do
get_random_viable_peer()
|> Enum.at(1)
|> elem(1)
end
But as commented, the implementation doesn't seems good. The idea is to fetch the best peers (ordered by delay) and to make our queries on the peer choosed (with his IP as our url).
Then it would be easy to make our queries, and then fallback on the best peer chosen if the first one failed.
We need to have a list of valid peers and switch between them if the used one encounter issues.
I've tried a first solution for this problem :
But as commented, the implementation doesn't seems good. The idea is to fetch the best peers (ordered by delay) and to make our queries on the peer choosed (with his IP as our url).
Then it would be easy to make our queries, and then fallback on the best peer chosen if the first one failed.