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:
parent
f903f8442a
commit
4930ba353e
4 changed files with 8 additions and 6 deletions
|
@ -16,7 +16,7 @@ distribute traffic more evenly across all instances and avoid performance
|
||||||
bottlenecks and rate-limiting.
|
bottlenecks and rate-limiting.
|
||||||
|
|
||||||
## Heroku deploy
|
## 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
|
you can encode your json at https://www.base64encode.org
|
||||||
|
|
||||||
## Standalone
|
## 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_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_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 | 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 |
|
||||||
|
|
|
@ -74,12 +74,13 @@ defmodule Farside.Application do
|
||||||
end
|
end
|
||||||
|
|
||||||
struct(%Service{}, service_atom)
|
struct(%Service{}, service_atom)
|
||||||
|> Http.fetch_instances()
|
|
||||||
|> Farside.Instance.Supervisor.start()
|
|> Farside.Instance.Supervisor.start()
|
||||||
|
|> Farside.Instances.sync()
|
||||||
end
|
end
|
||||||
|
|
||||||
LastUpdated.value(DateTime.utc_now())
|
LastUpdated.value(DateTime.utc_now())
|
||||||
|
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,7 +26,7 @@ defmodule Farside.Instance do
|
||||||
write_concurrency: true
|
write_concurrency: true
|
||||||
])
|
])
|
||||||
|
|
||||||
:ets.insert(ref, {:data, init_arg})
|
:ets.insert(ref, {:default, init_arg})
|
||||||
|
|
||||||
{:ok, %{type: init_arg.type, ref: ref}}
|
{:ok, %{type: init_arg.type, ref: ref}}
|
||||||
end
|
end
|
||||||
|
@ -59,13 +59,13 @@ defmodule Farside.Instance do
|
||||||
:update,
|
:update,
|
||||||
state
|
state
|
||||||
) do
|
) do
|
||||||
service = :ets.lookup(String.to_atom(state.type), :data)
|
service = :ets.lookup(String.to_atom(state.type), :default)
|
||||||
|
|
||||||
{_, service} = List.first(service)
|
{_, service} = List.first(service)
|
||||||
|
|
||||||
service = Http.fetch_instances(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})
|
:ets.insert(state.ref, {:data, service})
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
defmodule Farside.Instances do
|
defmodule Farside.Instances do
|
||||||
alias Farside.LastUpdated
|
alias Farside.LastUpdated
|
||||||
|
|
||||||
def sync() do
|
def sync(data \\ []) do
|
||||||
update_file = Application.fetch_env!(:farside, :update_file)
|
update_file = Application.fetch_env!(:farside, :update_file)
|
||||||
update_json = update_file <> ".json"
|
update_json = update_file <> ".json"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue