mirror of
https://github.com/benbusby/farside.git
synced 2025-03-14 19:26:30 -04:00
Broaden HTTPoison status code inspection
Rather than enforcing a 200 status code, the instance query is deemed a success if the status code is <400. Various services return 200-399 status codes that don't necessarily indicate an error, but may have to do with how the instance was configured.
This commit is contained in:
parent
71febe3d3b
commit
1fb9051ae1
@ -37,8 +37,9 @@ For example:
|
||||
The app runs with an internally scheduled cron task that queries all instances
|
||||
for services defined in [services.json](services.json) every 5 minutes. For
|
||||
each instance, as long as the instance takes <5 seconds to respond and returns
|
||||
a 200 status code, the instance is added to a list of available instances for
|
||||
that particular service. If not, it is discarded until the next update period.
|
||||
a successful response code, the instance is added to a list of available
|
||||
instances for that particular service. If not, it is discarded until the next
|
||||
update period.
|
||||
|
||||
Farside's routing is very minimal, with only the following routes:
|
||||
|
||||
|
@ -5,6 +5,8 @@ defmodule Farside.Instances do
|
||||
@service_prefix Application.fetch_env!(:farside, :service_prefix)
|
||||
@headers Application.fetch_env!(:farside, :headers)
|
||||
@queries Application.fetch_env!(:farside, :queries)
|
||||
@debug_header "======== "
|
||||
@debug_spacer " "
|
||||
|
||||
def sync() do
|
||||
File.rename(@update_file, "#{@update_file}-prev")
|
||||
@ -24,12 +26,16 @@ defmodule Farside.Instances do
|
||||
:good
|
||||
|
||||
true ->
|
||||
case HTTPoison.get(url, @headers) do
|
||||
{:ok, %HTTPoison.Response{status_code: 200}} ->
|
||||
# TODO: Add validation of results, not just status code
|
||||
HTTPoison.get(url, @headers)
|
||||
|> then(&elem(&1, 1))
|
||||
|> Map.get(:status_code)
|
||||
|> case do
|
||||
n when n < 400 ->
|
||||
IO.puts("#{@debug_spacer}✓ [#{n}]")
|
||||
:good
|
||||
|
||||
_ ->
|
||||
n ->
|
||||
IO.puts("#{@debug_spacer}x [#{(n && n) || "error"}]")
|
||||
:bad
|
||||
end
|
||||
end
|
||||
@ -41,7 +47,7 @@ defmodule Farside.Instances do
|
||||
|
||||
# Loop through all instances and check each for availability
|
||||
for service <- json do
|
||||
IO.puts("======== " <> service.type)
|
||||
IO.puts("#{@debug_header}#{service.type}")
|
||||
|
||||
result =
|
||||
Enum.filter(service.instances, fn instance_url ->
|
||||
@ -52,7 +58,7 @@ defmodule Farside.Instances do
|
||||
query: Enum.random(@queries)
|
||||
)
|
||||
|
||||
IO.puts(" " <> request_url)
|
||||
IO.puts("#{@debug_spacer}#{request_url}")
|
||||
|
||||
request(request_url) == :good
|
||||
end)
|
||||
|
Loading…
x
Reference in New Issue
Block a user