Skip to content

Draft: Use requirements attribute to start application in mix task

h3poteto requested to merge h3poteto/pleroma:fix/start-pleroma-mix-tasks into develop

I'm executing Pleroma on Elixir 1.13, and using config/runtime.exs for database configuration. For example,

config :pleroma, Pleroma.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: System.fetch_env!("DB_USER"),
  password: System.fetch_env!("DB_PASSWORD"),
  database: System.fetch_env!("DB_NAME"),
  hostname: System.fetch_env!("DB_HOST"),

In this situation, I couldn't execute some mix tasks because they can't read database configuration from runtime.exs.

$ mix pleroma.database prune_objects
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2887ms. This means requests are coming in and your connection pool cannot serve them fast enough. You can address this by:

  1. Ensuring your database is available and that you can connect to it
  2. Tracking down slow queries and making sure they are running fast enough
  3. Increasing the pool_size (albeit it increases resource consumption)
  4. Allowing requests to wait longer by increasing :queue_target and :queue_interval

See DBConnection.start_link/2 for more information

    (ecto_sql 3.6.2) lib/ecto/adapters/sql.ex:760: Ecto.Adapters.SQL.raise_sql_call_error/1
    (ecto_sql 3.6.2) lib/ecto/adapters/sql.ex:693: Ecto.Adapters.SQL.execute/5
    (pleroma 2.4.4-335-g5e147c2e-fix-tasks+dev) lib/mix/tasks/pleroma/database.ex:97: Mix.Tasks.Pleroma.Database.run/1
    (mix 1.11.3) lib/mix/task.ex:394: Mix.Task.run_task/3
    (mix 1.11.3) lib/mix/cli.ex:84: Mix.CLI.run_task/2
    (elixir 1.11.3) lib/code.ex:931: Code.require_file/2

If I move the database configuration to config/dev.exs, it works fine.


In the first place, how about using @requirements("app.start") attribute instead of start_pleroma? If I use the attribute, mix tasks can read database configuration from runtime.exs.

Merge request reports