Skip to content

Commit

Permalink
Add AppSignal metric
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineAugusti committed Dec 19, 2024
1 parent 35f64e7 commit 3c42587
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions apps/transport/lib/transport_web/plugs/worker_healthcheck.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 3c42587

Please sign in to comment.