From b0953f07779a4fc6fdfe650a872c4e39251db3ee Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Thu, 21 Oct 2021 21:15:58 -0600 Subject: Validate status code for all service instances 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. --- update.exs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'update.exs') diff --git a/update.exs b/update.exs index 6e42198..2387fb8 100644 --- a/update.exs +++ b/update.exs @@ -1,19 +1,31 @@ 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 x <- json do - IO.puts(x.instance_type) - for y <- x.instance_list do - IO.puts(" - " <> y) - end + 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 -- cgit v1.2.3