fix: auto-dismiss agent offline insights when agent reconnects

This commit is contained in:
Graham McIntire 2026-03-04 16:25:08 -06:00
parent 8109bd71c8
commit 11d976531b
No known key found for this signature in database

View file

@ -195,9 +195,32 @@ defmodule Towerops.Agents do
_ -> [last_seen_at: now, last_ip: ip_address]
end
AgentToken
|> where([t], t.id == ^agent_token_id)
|> Repo.update_all(set: updates)
result =
AgentToken
|> where([t], t.id == ^agent_token_id)
|> Repo.update_all(set: updates)
# Auto-dismiss agent offline insights when agent comes back online
dismiss_agent_offline_insights(agent_token_id)
result
end
defp dismiss_agent_offline_insights(agent_token_id) do
alias Towerops.Preseem.Insight
now = DateTime.truncate(DateTime.utc_now(), :second)
{count, _} =
Insight
|> where(agent_token_id: ^agent_token_id, type: "agent_offline", status: "active")
|> Repo.update_all(set: [status: "dismissed", dismissed_at: now])
if count > 0 do
Logger.info("Auto-dismissed #{count} agent offline insight(s) for agent #{agent_token_id}")
end
:ok
end
@doc """