mirror of
https://github.com/benbusby/farside.git
synced 2025-06-08 02:16:36 +00:00
add env var to control timeout
This commit is contained in:
parent
4930ba353e
commit
9b7c544466
4 changed files with 7 additions and 4 deletions
|
@ -142,5 +142,6 @@ goes against what Farside is trying to solve. Use at your own discretion.
|
|||
| -- | -- |
|
||||
| FARSIDE_TEST | If enabled, bypasses the instance availability check and adds all instances to the pool. |
|
||||
| FARSIDE_PORT | The port to run Farside on (default: `4001`) |
|
||||
| FARSIDE_TIMEOUT | The default timeout to wait for the url (default: `8000`) |
|
||||
| FARSIDE_SERVICES_JSON | The "services" JSON file to use for selecting instances (default: `services.json`) |
|
||||
| FARSIDE_SERVICES_JSON_DATA | The "services" JSON file to use for selecting instances base64 encoded |
|
||||
|
|
|
@ -14,4 +14,5 @@ config :farside,
|
|||
queries: [
|
||||
"weather",
|
||||
"time"
|
||||
]
|
||||
],
|
||||
recv_timeout: System.get_env("FARSIDE_TIMEOUT") || "8000"
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue