summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Busby <noreply+git@benbusby.com>2021-11-10 11:48:39 -0700
committerBen Busby <noreply+git@benbusby.com>2021-11-10 11:48:39 -0700
commitd334fc76950b54eb641627d016b28a4824cf2657 (patch)
tree933ee462e4b2603225a6f24362a6e9b75984ce16
parentf33279c41b17545bfbe7c0f9baa5d1b49c814a30 (diff)
downloadfarside-d334fc76950b54eb641627d016b28a4824cf2657.tar.gz
Move Service struct def to its own module
Service struct now defined in lib/service.ex This makes a bit more sense now that its a shared resource, rather than just defining it only in the update.exs script.
-rw-r--r--lib/service.ex6
-rw-r--r--update.exs15
2 files changed, 9 insertions, 12 deletions
diff --git a/lib/service.ex b/lib/service.ex
new file mode 100644
index 0000000..ae964f6
--- /dev/null
+++ b/lib/service.ex
@@ -0,0 +1,6 @@
+defmodule Service do
+ defstruct type: nil,
+ test_url: nil,
+ fallback: nil,
+ instances: []
+end
diff --git a/update.exs b/update.exs
index d89ffa8..7452e3d 100644
--- a/update.exs
+++ b/update.exs
@@ -1,12 +1,3 @@
-defmodule Service do
- defstruct [
- type: nil,
- test_url: nil,
- fallback: nil,
- instances: []
- ]
-end
-
defmodule Instances do
@fallback_str Application.fetch_env!(:farside, :fallback_str)
@update_file Application.fetch_env!(:farside, :update_file)
@@ -15,7 +6,7 @@ defmodule Instances do
def init() do
File.rename(@update_file, "#{@update_file}-prev")
- update(@services_json)
+ update
end
def request(url) do
@@ -33,8 +24,8 @@ defmodule Instances do
end
end
- def update(filename) do
- {:ok, file} = File.read(filename)
+ def update do
+ {:ok, file} = File.read(@services_json)
{:ok, json} = Poison.decode(file, as: [%Service{}])
# Loop through all instances and check each for availability