mirror of
https://github.com/benbusby/farside.git
synced 2025-05-04 01:20:02 +00:00
Display list of available instances on home page
This introduces a number of new changes: - Services are now inserted into redis with a prefix prepended to the key name. This allows for easier filtering to get only live instances. - The home page now uses an eex template for displaying all live instances for every service, determined by the last update - A "last_updated" field was added - farside.ex was added to contain all functionality related to querying for instances (WIP) - Other improvements
This commit is contained in:
parent
8042dcad0c
commit
56b9c52528
7 changed files with 131 additions and 12 deletions
14
update.exs
14
update.exs
|
@ -11,6 +11,7 @@ defmodule Instances do
|
|||
@fallback_str Application.fetch_env!(:farside, :fallback_str)
|
||||
@update_file Application.fetch_env!(:farside, :update_file)
|
||||
@services_json Application.fetch_env!(:farside, :services_json)
|
||||
@service_prefix Application.fetch_env!(:farside, :service_prefix)
|
||||
|
||||
def init() do
|
||||
File.rename(@update_file, "#{@update_file}-prev")
|
||||
|
@ -45,18 +46,16 @@ defmodule Instances do
|
|||
end
|
||||
|
||||
def add_to_redis(service, instances) do
|
||||
IO.puts " --------"
|
||||
IO.inspect "OK: " <> instances
|
||||
# Remove previous list of instances
|
||||
Redix.command(:redix, [
|
||||
"DEL",
|
||||
service.type
|
||||
"#{@service_prefix}#{service.type}"
|
||||
])
|
||||
|
||||
# Update with new list of available instances
|
||||
Redix.command(:redix, [
|
||||
"LPUSH",
|
||||
service.type
|
||||
"#{@service_prefix}#{service.type}"
|
||||
] ++ instances)
|
||||
|
||||
# Set fallback to one of the available instances,
|
||||
|
@ -84,3 +83,10 @@ defmodule Instances do
|
|||
end
|
||||
|
||||
Instances.init()
|
||||
|
||||
# Add UTC time of last update
|
||||
Redix.command(:redix, [
|
||||
"SET",
|
||||
"last_updated",
|
||||
Calendar.strftime(DateTime.utc_now(), "%c")
|
||||
])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue