Handle database metrics collection gracefully during startup

Check if Repo process is started before attempting to collect PostgreSQL
metrics. This prevents the 'could not lookup Ecto repo' error message
during application startup when the periodic metrics collector runs
before the Repo is fully initialized.

The metrics collection now silently skips when the Repo isn't ready
and will succeed on subsequent runs once the Repo is started.
This commit is contained in:
Graham McIntire 2025-10-25 17:47:08 -05:00
parent f211559d93
commit 974c61e549
No known key found for this signature in database

View file

@ -134,6 +134,18 @@ defmodule Aprsme.Telemetry.DatabaseMetrics do
end
defp do_collect_postgres_metrics do
# Check if Repo is started before collecting metrics
case Process.whereis(Aprsme.Repo) do
nil ->
# Repo not started yet, skip metrics collection silently
:ok
_pid ->
collect_database_metrics()
end
end
defp collect_database_metrics do
# Database size
case Aprsme.Repo.query("SELECT pg_database_size(current_database()) as size") do
{:ok, %{rows: [[size]]}} ->