fix(insights): add info logging to AI network insight worker

Info-level logs for: org count at start, observation count per org,
successful persistence, and dedup. Makes the worker observable without
needing database access.
This commit is contained in:
Graham McIntire 2026-05-11 10:11:16 -05:00
parent 4d91e691ad
commit 4bca41a700

View file

@ -37,6 +37,8 @@ defmodule Towerops.Workers.AiNetworkInsightWorker do
|> select([o], o.id)
|> Repo.all()
Logger.info("AI network insight: processing #{length(org_ids)} orgs")
Enum.each(org_ids, &process_organization/1)
:ok
@ -50,6 +52,10 @@ defmodule Towerops.Workers.AiNetworkInsightWorker do
{:ok, %{content: content, model: model} = response} ->
{:ok, observations} = NetworkInsightPrompt.parse(content)
Logger.info(
"AI network insight: org #{organization_id} got #{length(observations)} observations, #{Map.get(response, :completion_tokens) || 0} tokens"
)
Enum.each(observations, &persist_observation(organization_id, &1, model))
record_usage(organization_id, response, model)
@ -89,7 +95,11 @@ defmodule Towerops.Workers.AiNetworkInsightWorker do
}
case Insights.insert_insight_if_new(attrs) do
{:ok, _} ->
{:ok, :duplicate} ->
:ok
{:ok, insight} ->
Logger.info("AI network insight: persisted #{insight.id}\"#{obs.title}\"")
:ok
{:error, changeset} ->