configurable timeout

This commit is contained in:
Hakaba Hitoyo 2018-07-18 13:36:20 +09:00
parent e4dd58307a
commit b12d17d2ce
3 changed files with 10 additions and 5 deletions

View File

@ -98,7 +98,8 @@
config :pleroma, :suggestions, config :pleroma, :suggestions,
enabled: false, enabled: false,
third_party_engine: third_party_engine:
"http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-suggestions-api.cgi?{{host}}+{{user}}" "http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-suggestions-api.cgi?{{host}}+{{user}}",
timeout: 300_000
# Import environment specific config. This must remain at the bottom # Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above. # of this file so it overrides the configuration defined above.

View File

@ -1077,7 +1077,8 @@ def errors(conn, _) do
def suggestions(%{assigns: %{user: user}} = conn, _) do def suggestions(%{assigns: %{user: user}} = conn, _) do
if Keyword.get(@suggestions, :enabled, false) do if Keyword.get(@suggestions, :enabled, false) do
api = Keyword.get(@suggestions, :third_party_engine, false) api = Keyword.get(@suggestions, :third_party_engine, "")
timeout = Keyword.get(@suggestions, :timeout, 5000)
host = host =
Application.get_env(:pleroma, Pleroma.Web.Endpoint) Application.get_env(:pleroma, Pleroma.Web.Endpoint)
@ -1088,7 +1089,7 @@ def suggestions(%{assigns: %{user: user}} = conn, _) do
url = String.replace(api, "{{host}}", host) |> String.replace("{{user}}", user) url = String.replace(api, "{{host}}", host) |> String.replace("{{user}}", user)
with {:ok, %{status_code: 200, body: body}} <- with {:ok, %{status_code: 200, body: body}} <-
@httpoison.get(url, [], timeout: 300_000, recv_timeout: 300_000), @httpoison.get(url, [], timeout: timeout, recv_timeout: timeout),
{:ok, data} <- Jason.decode(body) do {:ok, data} <- Jason.decode(body) do
data2 = data2 =
Enum.slice(data, 0, 40) Enum.slice(data, 0, 40)

View File

@ -45,8 +45,11 @@ def nodeinfo(conn, %{"version" => "2.0"}) do
metadata: %{ metadata: %{
nodeName: Keyword.get(instance, :name), nodeName: Keyword.get(instance, :name),
mediaProxy: Keyword.get(media_proxy, :enabled), mediaProxy: Keyword.get(media_proxy, :enabled),
suggestions: Keyword.get(suggestions, :enabled, false), suggestions: %{
suggestionsThirdPartyEngine: Keyword.get(suggestions, :third_party_engine, false) enabled: Keyword.get(suggestions, :enabled, false),
thirdPartyEngine: Keyword.get(suggestions, :third_party_engine, ""),
timeout: Keyword.get(suggestions, :timeout, 5000)
}
} }
} }