fix: prevent telemetry errors when Exq is not running

- Check if Exq process is running before attempting to collect metrics
- Change rescue to catch to handle process exits (:noproc)
- Prevents error logs in environments where Exq is not configured
This commit is contained in:
Graham McIntire 2026-01-18 10:00:14 -06:00
parent 9b613f7a40
commit a85085c3ed
No known key found for this signature in database

View file

@ -135,12 +135,9 @@ defmodule ToweropsWeb.Telemetry do
Publishes Exq queue and process statistics.
"""
def publish_exq_stats do
# Only run if Exq is available (not in test env)
if Application.get_env(:towerops, :env) == :test do
# Only run if Exq is available (not in test env) and the process is running
if Application.get_env(:towerops, :env) == :test or not Process.whereis(Exq) do
:ok
# Get stats for each queue
# Get process stats
else
try do
queues = ["default", "discovery", "polling", "monitoring", "maintenance"]
@ -171,8 +168,9 @@ defmodule ToweropsWeb.Telemetry do
)
:ok
rescue
_ -> :ok
catch
# Catch exits (like :noproc) and exceptions
_, _ -> :ok
end
end
end