summaryrefslogtreecommitdiff
path: root/update.exs
diff options
context:
space:
mode:
authorBen Busby <noreply+git@benbusby.com>2021-11-08 17:08:19 -0700
committerBen Busby <noreply+git@benbusby.com>2021-11-08 17:08:19 -0700
commit56b9c52528d1e514d4ec15f1da7517cd83bcf5ff (patch)
treeb7a5c0f8015bba7b47fb1e72577ea4eb9c7e99c2 /update.exs
parent8042dcad0c61110111949a856c935325ca65f8ef (diff)
downloadfarside-56b9c52528d1e514d4ec15f1da7517cd83bcf5ff.tar.gz
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
Diffstat (limited to 'update.exs')
-rw-r--r--update.exs14
1 files changed, 10 insertions, 4 deletions
diff --git a/update.exs b/update.exs
index fe1445b..4e95392 100644
--- a/update.exs
+++ b/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")
+])