diff --git a/README.md b/README.md index b14f225..a42d582 100644 --- a/README.md +++ b/README.md @@ -27,3 +27,8 @@ If [available in Hex](https://hex.pm/docs/publish), the package can be installed config :big_query, bigquery_scope: "https://www.googleapis.com/auth/drive" + + 5. If you have long running requests - you can override the timeout of the http calls (in MS): + + config :big_query, + bigquery_request_timeout: 60000 diff --git a/lib/big_query/resource.ex b/lib/big_query/resource.ex index 8333e63..e8b1051 100644 --- a/lib/big_query/resource.ex +++ b/lib/big_query/resource.ex @@ -4,6 +4,8 @@ defmodule BigQuery.Resource do @type headers :: [{String.t, String.t}] @type response :: %{status_code: integer, body: String.t, headers: headers} + def timeout, do: Application.get_env(:big_query, :bigquery_request_timeout, 120_000) + defmacro __using__(_opts) do quote do @bigquery_url "https://www.googleapis.com/bigquery/v2" @@ -16,7 +18,7 @@ defmodule BigQuery.Resource do end @spec get(String.t, headers, [timeout: integer]) :: {:ok, response} | {:error, String.t} - def get(url, headers \\ [], opts \\ [timeout: 120_000]) do + def get(url, headers \\ [], opts \\ [timeout: timeout()]) do case TokenServer.get_token() do {:ok, access_token} -> headers = headers @@ -33,7 +35,7 @@ defmodule BigQuery.Resource do end @spec post(String.t, any, [{String.t, String.t}], [timeout: integer]) :: {:ok, response} | {:error, String.t} - def post(url, body \\ nil, headers \\ [], opts \\ [timeout: 120_000]) do + def post(url, body \\ nil, headers \\ [], opts \\ [timeout: timeout()]) do case TokenServer.get_token() do {:ok, access_token} -> headers = headers @@ -51,7 +53,7 @@ defmodule BigQuery.Resource do end @spec delete(String.t, [{String.t, String.t}], [timeout: integer]) :: {:ok, response} | {:error, String.t} - def delete(url, headers \\ [], opts \\ [timeout: 120_000]) do + def delete(url, headers \\ [], opts \\ [timeout: timeout()]) do case TokenServer.get_token() do {:ok, access_token} -> headers = headers @@ -109,4 +111,4 @@ defmodule BigQuery.Resource do _ -> headers end end -end \ No newline at end of file +end