From 3c425875b0215e1d8bfa7d6062dd5c5e0a211381 Mon Sep 17 00:00:00 2001 From: Antoine Augusti Date: Thu, 19 Dec 2024 15:35:14 +0100 Subject: [PATCH] Add AppSignal metric --- .../transport/lib/transport_web/plugs/worker_healthcheck.ex | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/transport/lib/transport_web/plugs/worker_healthcheck.ex b/apps/transport/lib/transport_web/plugs/worker_healthcheck.ex index c5604d899e..fedbc61644 100644 --- a/apps/transport/lib/transport_web/plugs/worker_healthcheck.ex +++ b/apps/transport/lib/transport_web/plugs/worker_healthcheck.ex @@ -22,6 +22,7 @@ defmodule TransportWeb.Plugs.WorkerHealthcheck do {mod, fun} = opts[:if] if apply(mod, fun, []) do + store_last_attempted_at_delay_metric() status_code = if healthy_state?(), do: 200, else: 503 conn @@ -40,6 +41,11 @@ defmodule TransportWeb.Plugs.WorkerHealthcheck do end end + def store_last_attempted_at_delay_metric do + value = DateTime.diff(oban_last_attempted_at(), DateTime.utc_now(), :second) + Appsignal.add_distribution_value("oban.last_attempted_at_delay", value) + end + def healthy_state? do app_started_recently?() or oban_attempted_jobs_recently?() end