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_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_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 | 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 |
|
| FARSIDE_SERVICES_JSON_DATA | The "services" JSON file to use for selecting instances base64 encoded |
|
||||||
|
|
|
@ -14,4 +14,5 @@ config :farside,
|
||||||
queries: [
|
queries: [
|
||||||
"weather",
|
"weather",
|
||||||
"time"
|
"time"
|
||||||
]
|
],
|
||||||
|
recv_timeout: System.get_env("FARSIDE_TIMEOUT") || "8000"
|
|
@ -3,4 +3,4 @@ import Config
|
||||||
config :farside,
|
config :farside,
|
||||||
port: System.get_env("FARSIDE_PORT", nil),
|
port: System.get_env("FARSIDE_PORT", nil),
|
||||||
services_json: System.get_env("FARSIDE_SERVICES_JSON", "services.json"),
|
services_json: System.get_env("FARSIDE_SERVICES_JSON", "services.json"),
|
||||||
services_json_data: System.get_env("FARSIDE_SERVICES_JSON_DATA") || ""
|
services_json_data: System.get_env("FARSIDE_SERVICES_JSON_DATA") || ""
|
|
@ -3,6 +3,7 @@ defmodule Farside.Http do
|
||||||
|
|
||||||
@headers Application.fetch_env!(:farside, :headers)
|
@headers Application.fetch_env!(:farside, :headers)
|
||||||
@queries Application.fetch_env!(:farside, :queries)
|
@queries Application.fetch_env!(:farside, :queries)
|
||||||
|
@recv_timeout String.to_integer(Application.fetch_env!(:farside, :recv_timeout))
|
||||||
|
|
||||||
def request(url) do
|
def request(url) do
|
||||||
cond do
|
cond do
|
||||||
|
@ -31,7 +32,7 @@ defmodule Farside.Http do
|
||||||
:good
|
:good
|
||||||
|
|
||||||
true ->
|
true ->
|
||||||
HTTPoison.get(url, @headers)
|
HTTPoison.get(url, @headers, timeout: 5000, recv_timeout: @recv_timeout)
|
||||||
|> then(&elem(&1, 1))
|
|> then(&elem(&1, 1))
|
||||||
|> Map.get(:status_code)
|
|> Map.get(:status_code)
|
||||||
|> case do
|
|> case do
|
||||||
|
@ -61,7 +62,7 @@ defmodule Farside.Http do
|
||||||
{test_url, reply, instance}
|
{test_url, reply, instance}
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|> Task.yield_many(5000)
|
|> Task.yield_many(@recv_timeout)
|
||||||
|> Enum.map(fn {task, res} ->
|
|> Enum.map(fn {task, res} ->
|
||||||
# Shut down the tasks that did not reply nor exit
|
# Shut down the tasks that did not reply nor exit
|
||||||
res || Task.shutdown(task, :brutal_kill)
|
res || Task.shutdown(task, :brutal_kill)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue