1
0
Fork 0
mirror of https://github.com/benbusby/farside.git synced 2025-06-08 10:26:36 +00:00

fix init/update logic

This commit is contained in:
mithereal 2022-07-31 14:38:50 -07:00
parent f903f8442a
commit 4930ba353e
4 changed files with 8 additions and 6 deletions

View file

@ -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

View file

@ -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})

View file

@ -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"