1
0
Fork 0
mirror of https://github.com/benbusby/farside.git synced 2025-06-08 10:26:36 +00:00

add env var to control timeout

This commit is contained in:
mithereal 2022-07-31 15:14:48 -07:00
parent 4930ba353e
commit 9b7c544466
4 changed files with 7 additions and 4 deletions

View file

@ -3,6 +3,7 @@ defmodule Farside.Http do
@headers Application.fetch_env!(:farside, :headers)
@queries Application.fetch_env!(:farside, :queries)
@recv_timeout String.to_integer(Application.fetch_env!(:farside, :recv_timeout))
def request(url) do
cond do
@ -31,7 +32,7 @@ defmodule Farside.Http do
:good
true ->
HTTPoison.get(url, @headers)
HTTPoison.get(url, @headers, timeout: 5000, recv_timeout: @recv_timeout)
|> then(&elem(&1, 1))
|> Map.get(:status_code)
|> case do
@ -61,7 +62,7 @@ defmodule Farside.Http do
{test_url, reply, instance}
end)
end)
|> Task.yield_many(5000)
|> Task.yield_many(@recv_timeout)
|> Enum.map(fn {task, res} ->
# Shut down the tasks that did not reply nor exit
res || Task.shutdown(task, :brutal_kill)