From 974c61e549c2c5b3a113b33af3358d7ce3eba428 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sat, 25 Oct 2025 17:47:08 -0500 Subject: [PATCH] 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. --- lib/aprsme/telemetry/database_metrics.ex | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/aprsme/telemetry/database_metrics.ex b/lib/aprsme/telemetry/database_metrics.ex index bfd9b14..91879ca 100644 --- a/lib/aprsme/telemetry/database_metrics.ex +++ b/lib/aprsme/telemetry/database_metrics.ex @@ -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]]}} ->