Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ku1ik committed Jul 1, 2024
1 parent 2e57d97 commit c870219
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ config :asciinema, Asciinema.Repo,
database: "asciinema_development",
stacktrace: true,
show_sensitive_data_on_connection_error: true,
pool_size: 10
pool_size: 11

secret_key_base = "60BnXnzGGwwiZj91YA9XYKF9BCiM7lQ/1um8VXcWWLSdUp9OcPZV6YnQv7eFTYSY"

Expand Down
19 changes: 0 additions & 19 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@ import Config

env = &System.get_env/1

if config_env() == :prod do
database_url =
System.get_env("DATABASE_URL") ||
raise """
environment variable DATABASE_URL is missing.
For example: ecto://USER:PASS@HOST/DATABASE
"""

config :asciinema, Asciinema.Repo, url: database_url
end

if config_env() in [:prod, :dev] do
if secret_key_base = env.("SECRET_KEY_BASE") do
config :asciinema, Asciinema.Accounts, secret: secret_key_base
Expand Down Expand Up @@ -74,14 +63,6 @@ if config_env() in [:prod, :dev] do
end
end

if db_pool_size = env.("DB_POOL_SIZE") do
config :asciinema, Asciinema.Repo, pool_size: String.to_integer(db_pool_size)
end

if env.("ECTO_IPV6") in ~w(true 1) do
config :asciinema, Asciinema.Repo, socket_options: [:inet6]
end

if smtp_host = env.("SMTP_HOST") do
config :asciinema, Asciinema.Emails.Mailer,
adapter: Swoosh.Adapters.SMTP,
Expand Down
5 changes: 4 additions & 1 deletion lib/asciinema/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ defmodule Asciinema.Application do
def start(_type, _args) do
:ok = Oban.Telemetry.attach_default_logger()
:ok = Asciinema.ObanErrorReporter.configure()
# rr = take_app_env(Asciinema.Repo)
rr = Application.fetch_env!(:asciinema, Asciinema.Repo)
IO.inspect(rr, label: "rr")

# List all child processes to be supervised
children = [
Expand All @@ -23,7 +26,7 @@ defmodule Asciinema.Application do
# Start telemetry reporters
Asciinema.Telemetry,
# Start the Ecto repository
Asciinema.Repo,
{Asciinema.Repo, rr},
# Start PNG generator poolboy pool
:poolboy.child_spec(:worker, Asciinema.PngGenerator.Rsvg.poolboy_config(), []),
# Start Oban
Expand Down
20 changes: 20 additions & 0 deletions lib/asciinema/repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ defmodule Asciinema.Repo do

use Scrivener, page_size: 10

def init(_type, config) do
config = Keyword.put(config, :url, System.get_env("DATABASE_URL"))

config =
if pool_size = System.get_env("DB_POOL_SIZE") do
Keyword.put(config, :pool_size, String.to_integer(pool_size))
else
config
end

config =
if System.get_env("ECTO_IPV6") in ~w(true 1) do
Keyword.put(config, :socket_options, [:inet6])
else
config
end

{:ok, config}
end

def transact(fun, opts \\ []) do
transaction(
fn ->
Expand Down

0 comments on commit c870219

Please sign in to comment.