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:
parent
f211559d93
commit
974c61e549
1 changed files with 12 additions and 0 deletions
|
|
@ -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]]}} ->
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue