mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 05:37:59 +01:00
Add Req backend for ExAws
This commit is contained in:
parent
6170e0b5dd
commit
29dc68c714
2 changed files with 34 additions and 9 deletions
|
@ -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,
|
||||
|
|
31
lib/philomena_media/req.ex
Normal file
31
lib/philomena_media/req.ex
Normal file
|
@ -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
|
Loading…
Reference in a new issue