36 lines
2.1 KiB
Go
36 lines
2.1 KiB
Go
package models
|
|
|
|
import "time"
|
|
|
|
// AIAgentRun is one task an AI_engine agent finished, recorded from its
|
|
// `telemetry.task` event (internal/ai/telemetry). Phase 4 of
|
|
// krow_talent_app/docs/agent-platform-plan.md: before this, a run existed only
|
|
// as a log line and an ephemeral NATS message, so nothing could say how often
|
|
// an agent ran or how often it failed.
|
|
//
|
|
// Append-only, and pruned after 30 days. Live agent STATE (the 5-second
|
|
// `telemetry.agent` heartbeat) is deliberately not stored here — it is
|
|
// ephemeral and lives in Redis.
|
|
type AIAgentRun struct {
|
|
Runid int64 `json:"runid" gorm:"primaryKey;column:runid;autoIncrement"`
|
|
Agentid string `json:"agentid" gorm:"column:agentid;size:64;not null;index:idx_aiagentruns_agent_received,priority:1;uniqueIndex:uq_aiagentruns_agent_task,priority:1"`
|
|
// Taskid is the engine's task id. Null when the event carried none; the
|
|
// unique index then does not apply (Postgres treats NULLs as distinct), so
|
|
// a redelivered event with an id is stored once and one without is not lost.
|
|
Taskid *string `json:"taskid" gorm:"column:taskid;size:64;uniqueIndex:uq_aiagentruns_agent_task,priority:2"`
|
|
Tasktype string `json:"tasktype" gorm:"column:tasktype;size:64"`
|
|
Status string `json:"status" gorm:"column:status;size:20;not null"` // completed, failed
|
|
Error string `json:"error" gorm:"column:error;type:text"`
|
|
// Durationms is how long the task ran, as the engine measured it.
|
|
Durationms int `json:"durationms" gorm:"column:durationms"`
|
|
// Occurredat is the engine's own timestamp, kept for display only: it is a
|
|
// naive local time from whatever clock and zone the engine host runs.
|
|
// Windows and ordering use Receivedat, which is this backend's clock as a
|
|
// true instant (time.Now) — the column is timestamptz, so utils.DBNow's
|
|
// IST-digits-labelled-UTC value would be 5h30m off here.
|
|
Occurredat *time.Time `json:"occurredat" gorm:"column:occurredat"`
|
|
Receivedat time.Time `json:"receivedat" gorm:"column:receivedat;not null;index:idx_aiagentruns_agent_received,priority:2;index:idx_aiagentruns_received"`
|
|
}
|
|
|
|
func (AIAgentRun) TableName() string { return "aiagentruns" }
|