mirror of
https://github.com/benbusby/farside.git
synced 2025-03-15 03:36:33 -04:00

Updated to filter out all instances that either time out (I believe default timeout for HTTPoison is 5s) or return a non-200 status code.
34 lines
753 B
Elixir
34 lines
753 B
Elixir
defmodule Instance do
|
|
defstruct [
|
|
instance_type: nil,
|
|
instance_test: nil,
|
|
instance_list: []
|
|
]
|
|
end
|
|
|
|
defmodule Instances do
|
|
def request(url) do
|
|
case HTTPoison.get(url) do
|
|
{:ok, %HTTPoison.Response{status_code: 200}} ->
|
|
# TODO: Add validation of results, not just status code
|
|
:good
|
|
_ ->
|
|
:bad
|
|
end
|
|
end
|
|
|
|
def update(filename) do
|
|
{:ok, file} = File.read(filename)
|
|
{:ok, json} = Poison.decode(file, as: [%Instance{}])
|
|
for service <- json do
|
|
result = Enum.filter(service.instance_list, fn(url) ->
|
|
request(url <> service.instance_test) == :good
|
|
end)
|
|
# TODO: Output result to redis
|
|
IO.inspect(result)
|
|
end
|
|
end
|
|
end
|
|
|
|
Instances.update("instances.json")
|