diff --git a/config/runtime.exs b/config/runtime.exs index 935ba124..190a1da7 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -74,8 +74,7 @@ config :philomena, :s3_primary_options, host: System.fetch_env!("S3_HOST"), port: System.fetch_env!("S3_PORT"), access_key_id: System.fetch_env!("AWS_ACCESS_KEY_ID"), - secret_access_key: System.fetch_env!("AWS_SECRET_ACCESS_KEY"), - http_opts: [timeout: 180_000, recv_timeout: 180_000] + secret_access_key: System.fetch_env!("AWS_SECRET_ACCESS_KEY") config :philomena, :s3_primary_bucket, System.fetch_env!("S3_BUCKET") @@ -85,8 +84,7 @@ config :philomena, :s3_secondary_options, host: System.get_env("ALT_S3_HOST"), port: System.get_env("ALT_S3_PORT"), access_key_id: System.get_env("ALT_AWS_ACCESS_KEY_ID"), - secret_access_key: System.get_env("ALT_AWS_SECRET_ACCESS_KEY"), - http_opts: [timeout: 180_000, recv_timeout: 180_000] + secret_access_key: System.get_env("ALT_AWS_SECRET_ACCESS_KEY") config :philomena, :s3_secondary_bucket, System.get_env("ALT_S3_BUCKET") @@ -94,11 +92,7 @@ config :philomena, :s3_secondary_bucket, System.get_env("ALT_S3_BUCKET") config :elastix, httpoison_options: [ssl: [verify: :verify_none]] -config :ex_aws, :hackney_opts, - timeout: 180_000, - recv_timeout: 180_000, - use_default_pool: false, - pool: false +config :ex_aws, http_client: PhilomenaMedia.Req config :ex_aws, :retries, max_attempts: 20, diff --git a/lib/philomena_media/req.ex b/lib/philomena_media/req.ex new file mode 100644 index 00000000..ff92d949 --- /dev/null +++ b/lib/philomena_media/req.ex @@ -0,0 +1,31 @@ +defmodule PhilomenaMedia.Req do + @behaviour ExAws.Request.HttpClient + + @moduledoc """ + Configuration for `m:Req`. + + Options can be set for `m:Req` with the following config: + + config :philomena, :req_opts, + receive_timeout: 30_000 + + The default config handles setting the above. + """ + + @default_opts [receive_timeout: 30_000] + + @impl true + def request(method, url, body \\ "", headers \\ [], http_opts \\ []) do + [method: method, url: url, body: body, headers: headers, decode_body: false] + |> Keyword.merge(Application.get_env(:philomena, :req_opts, @default_opts)) + |> Keyword.merge(http_opts) + |> Req.request() + |> case do + {:ok, %{status: status, headers: headers, body: body}} -> + {:ok, %{status_code: status, headers: headers, body: body}} + + {:error, reason} -> + {:error, %{reason: reason}} + end + end +end