Skip to content

Commit

Permalink
allow to configure Finch pools
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslandoga committed Jun 24, 2024
1 parent 59b1811 commit 46f9ba3
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions lib/plausible/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -119,51 +119,60 @@ defmodule Plausible.Application do
end

defp finch_pool_config() do
base_config = %{
"https://icons.duckduckgo.com" => [
conn_opts: [transport_opts: [timeout: 15_000]]
]
}
default = Application.get_env(:plausible, Plausible.Finch) || []

base_config =
%{
:default => default,
"https://icons.duckduckgo.com" =>
Config.Reader.merge(default, conn_opts: [transport_opts: [timeout: 15_000]])
}

base_config
|> maybe_add_sentry_pool()
|> maybe_add_paddle_pool()
|> maybe_add_google_pools()
|> maybe_add_sentry_pool(default)
|> maybe_add_paddle_pool(default)
|> maybe_add_google_pools(default)
end

defp maybe_add_sentry_pool(pool_config) do
defp maybe_add_sentry_pool(pool_config, default) do
case Sentry.Config.dsn() do
{"http" <> _rest = url, _, _} ->
Map.put(pool_config, url, size: 50)
Map.put(pool_config, url, Config.Reader.merge(default, size: 50))

nil ->
pool_config
end
end

defp maybe_add_paddle_pool(pool_config) do
defp maybe_add_paddle_pool(pool_config, default) do
paddle_conf = Application.get_env(:plausible, :paddle)

cond do
paddle_conf[:vendor_id] && paddle_conf[:vendor_auth_code] ->
Map.put(pool_config, Plausible.Billing.PaddleApi.vendors_domain(),
conn_opts: [transport_opts: [timeout: 15_000]]
Map.put(
pool_config,
Plausible.Billing.PaddleApi.vendors_domain(),
Config.Reader.merge(default, conn_opts: [transport_opts: [timeout: 15_000]])
)

true ->
pool_config
end
end

defp maybe_add_google_pools(pool_config) do
defp maybe_add_google_pools(pool_config, default) do
google_conf = Application.get_env(:plausible, :google)

cond do
google_conf[:client_id] && google_conf[:client_secret] ->
pool_config
|> Map.put(google_conf[:api_url], conn_opts: [transport_opts: [timeout: 15_000]])
|> Map.put(google_conf[:reporting_api_url],
conn_opts: [transport_opts: [timeout: 15_000]]
|> Map.put(
google_conf[:api_url],
Config.Reader.merge(default, conn_opts: [transport_opts: [timeout: 15_000]])
)
|> Map.put(
google_conf[:reporting_api_url],
Config.Reader.merge(default, conn_opts: [transport_opts: [timeout: 15_000]])
)

true ->
Expand Down

0 comments on commit 46f9ba3

Please sign in to comment.