Skip to content

Commit

Permalink
make db timeout configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
eliknebel committed Mar 14, 2024
1 parent 3dc5727 commit 285e767
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
# from environment variables at runtime
import Config

get_env_as_string = fn key, default ->
System.get_env(key, default)
|> String.trim()
|> String.downcase()
end

get_env_as_boolean = fn key, default ->
System.get_env(key, default)
|> String.downcase()
Expand All @@ -12,6 +18,11 @@ get_env_as_boolean = fn key, default ->
end
end

get_env_as_integer = fn key, default ->
System.get_env(key, default)
|> String.to_integer()
end

# Appsignal client key is required for appsignal integration
config :appsignal, :client_key, System.get_env("APPSIGNAL_PUSH_API_KEY", nil)

Expand Down Expand Up @@ -39,11 +50,17 @@ if config_env() == :prod do

maybe_ipv6 = if System.get_env("ECTO_IPV6") in ~w(true 1), do: [:inet6], else: []

db_timeout =
case get_env_as_string("DB_TIMEOUT", "600000") do
"infinity" -> :infinity
val -> String.to_integer(val)
end

config :oli, Oli.Repo,
url: database_url,
database: System.get_env("DB_NAME", "oli"),
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
timeout: 600_000,
timeout: db_timeout,
ownership_timeout: 600_000,
socket_options: maybe_ipv6

Expand Down

0 comments on commit 285e767

Please sign in to comment.