From 56b9c52528d1e514d4ec15f1da7517cd83bcf5ff Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Mon, 8 Nov 2021 17:08:19 -0700 Subject: 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 --- update.exs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'update.exs') 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") +]) -- cgit v1.2.3