diff --git a/README.md b/README.md index 4ad09f6..3474d2a 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ distribute traffic more evenly across all instances and avoid performance bottlenecks and rate-limiting. ## Heroku deploy -To load custom services, you must paste a base64 encoded string into the FARSIDE_SERVICES_JSON field +To load custom services, you must paste a base64 encoded json into the FARSIDE_SERVICES_JSON_DATA field you can encode your json at https://www.base64encode.org ## Standalone @@ -143,3 +143,4 @@ goes against what Farside is trying to solve. Use at your own discretion. | FARSIDE_TEST | If enabled, bypasses the instance availability check and adds all instances to the pool. | | FARSIDE_PORT | The port to run Farside on (default: `4001`) | | FARSIDE_SERVICES_JSON | The "services" JSON file to use for selecting instances (default: `services.json`) | +| FARSIDE_SERVICES_JSON_DATA | The "services" JSON file to use for selecting instances base64 encoded | diff --git a/lib/farside/application.ex b/lib/farside/application.ex index b32bfac..db7f894 100644 --- a/lib/farside/application.ex +++ b/lib/farside/application.ex @@ -74,12 +74,13 @@ defmodule Farside.Application do end struct(%Service{}, service_atom) - |> Http.fetch_instances() |> Farside.Instance.Supervisor.start() + |> Farside.Instances.sync() end LastUpdated.value(DateTime.utc_now()) response end + end diff --git a/lib/farside/instance.ex b/lib/farside/instance.ex index 9f69e42..498d9af 100644 --- a/lib/farside/instance.ex +++ b/lib/farside/instance.ex @@ -26,7 +26,7 @@ defmodule Farside.Instance do write_concurrency: true ]) - :ets.insert(ref, {:data, init_arg}) + :ets.insert(ref, {:default, init_arg}) {:ok, %{type: init_arg.type, ref: ref}} end @@ -59,13 +59,13 @@ defmodule Farside.Instance do :update, state ) do - service = :ets.lookup(String.to_atom(state.type), :data) + service = :ets.lookup(String.to_atom(state.type), :default) {_, service} = List.first(service) service = Http.fetch_instances(service) - :ets.delete_all_objects(String.to_atom(state.type)) + :ets.delete(String.to_atom(state.type), :data) :ets.insert(state.ref, {:data, service}) diff --git a/lib/farside/instances.ex b/lib/farside/instances.ex index f615707..b889cf5 100644 --- a/lib/farside/instances.ex +++ b/lib/farside/instances.ex @@ -1,7 +1,7 @@ defmodule Farside.Instances do alias Farside.LastUpdated - def sync() do + def sync(data \\ []) do update_file = Application.fetch_env!(:farside, :update_file) update_json = update_file <> ".json"