mirror of
https://github.com/benbusby/farside.git
synced 2025-06-08 10:26:36 +00:00
config option update_file now contains updated json of working instances after sync
This commit is contained in:
parent
a6e0c34abe
commit
ca1e96470d
5 changed files with 22 additions and 9 deletions
|
@ -92,4 +92,17 @@ defmodule Farside do
|
|||
instance
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def save_results(file, data) do
|
||||
{:ok, file} = File.open(file, [:append])
|
||||
bin = :erlang.term_to_binary(data)
|
||||
IO.binwrite(file, bin)
|
||||
File.close(file)
|
||||
end
|
||||
|
||||
def restore_term(file) do
|
||||
{:ok,bin} = File.read(file)
|
||||
:erlang.binary_to_term(bin)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ defmodule Farside.Application do
|
|||
def start(_type, _args) do
|
||||
port =
|
||||
case Application.fetch_env!(:farside, :port) do
|
||||
nil -> System.get_env("PORT")
|
||||
nil -> System.get_env("PORT", "4001")
|
||||
port -> port
|
||||
end
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ defmodule Farside.Instance do
|
|||
alias Farside.Http
|
||||
|
||||
@registry_name :servers
|
||||
@update_file Application.fetch_env!(:farside, :update_file)
|
||||
@update_file Application.fetch_env!(:farside, :update_file) <> ".json"
|
||||
|
||||
def child_spec(args) do
|
||||
%{
|
||||
|
@ -69,7 +69,9 @@ defmodule Farside.Instance do
|
|||
|
||||
:ets.insert(state.ref, {:data, service})
|
||||
|
||||
File.write(@update_file, service.fallback)
|
||||
encoded = service |> Map.from_struct() |> Jason.encode!()
|
||||
|
||||
Farside.save_results(@update_file, encoded)
|
||||
|
||||
{:noreply, state}
|
||||
end
|
||||
|
|
|
@ -3,15 +3,13 @@ defmodule Farside.Instances do
|
|||
|
||||
def sync() do
|
||||
update_file = Application.fetch_env!(:farside, :update_file)
|
||||
update_json = update_file <> ".json"
|
||||
|
||||
File.rm("#{update_file}-prev")
|
||||
File.rename(update_json, "#{update_file}-#{to_string(DateTime.utc_now()) <> ".json"}")
|
||||
|
||||
File.rename(update_file, "#{update_file}-prev")
|
||||
|
||||
File.write(update_file, "")
|
||||
File.write(update_json, "")
|
||||
|
||||
LastUpdated.value(DateTime.utc_now())
|
||||
|
||||
Farside.Instance.Supervisor.update_children()
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue