mirror of
https://github.com/benbusby/farside.git
synced 2025-04-20 02:48:42 +00:00
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.
This commit is contained in:
parent
f33279c41b
commit
d334fc7695
2 changed files with 9 additions and 12 deletions
6
lib/service.ex
Normal file
6
lib/service.ex
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
defmodule Service do
|
||||||
|
defstruct type: nil,
|
||||||
|
test_url: nil,
|
||||||
|
fallback: nil,
|
||||||
|
instances: []
|
||||||
|
end
|
15
update.exs
15
update.exs
|
@ -1,12 +1,3 @@
|
||||||
defmodule Service do
|
|
||||||
defstruct [
|
|
||||||
type: nil,
|
|
||||||
test_url: nil,
|
|
||||||
fallback: nil,
|
|
||||||
instances: []
|
|
||||||
]
|
|
||||||
end
|
|
||||||
|
|
||||||
defmodule Instances do
|
defmodule Instances do
|
||||||
@fallback_str Application.fetch_env!(:farside, :fallback_str)
|
@fallback_str Application.fetch_env!(:farside, :fallback_str)
|
||||||
@update_file Application.fetch_env!(:farside, :update_file)
|
@update_file Application.fetch_env!(:farside, :update_file)
|
||||||
|
@ -15,7 +6,7 @@ defmodule Instances do
|
||||||
|
|
||||||
def init() do
|
def init() do
|
||||||
File.rename(@update_file, "#{@update_file}-prev")
|
File.rename(@update_file, "#{@update_file}-prev")
|
||||||
update(@services_json)
|
update
|
||||||
end
|
end
|
||||||
|
|
||||||
def request(url) do
|
def request(url) do
|
||||||
|
@ -33,8 +24,8 @@ defmodule Instances do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update(filename) do
|
def update do
|
||||||
{:ok, file} = File.read(filename)
|
{:ok, file} = File.read(@services_json)
|
||||||
{:ok, json} = Poison.decode(file, as: [%Service{}])
|
{:ok, json} = Poison.decode(file, as: [%Service{}])
|
||||||
|
|
||||||
# Loop through all instances and check each for availability
|
# Loop through all instances and check each for availability
|
||||||
|
|
Loading…
Add table
Reference in a new issue