show fallback if there are no instances avail

This commit is contained in:
mithereal 2022-07-31 15:57:17 -07:00
parent 9b7c544466
commit e2ca414f79
3 changed files with 12 additions and 2 deletions

1
.envrc
View File

@ -1 +1,2 @@
export FARSIDE_PORT="4001"
export FARSIDE_TIMEOUT="10000"

View File

@ -6,7 +6,7 @@
"keywords": ["elixir", "farside" ],
"env": {
"MIX_ENV": "prod",
"FARSIDE_SERVICES_JSON": {
"FARSIDE_SERVICES_JSON_DATA": {
"description": "The base64(json) of services available (https://www.base64encode.org)",
"value": "",
"required": false

View File

@ -39,6 +39,15 @@ defmodule Farside do
|> Enum.reduce(%{}, fn service, acc ->
{_, data} = :ets.lookup(String.to_atom(service), :data) |> List.first()
instances =
case Enum.count(data.instances) == 0 do
true ->
[data.fallback]
false ->
data.instances
end
Map.put(
acc,
String.replace_prefix(
@ -46,7 +55,7 @@ defmodule Farside do
@service_prefix,
""
),
data.instances
instances
)
end)
end