server/ws: persist repo.stats into host_repo_stats
This commit is contained in:
@@ -267,8 +267,34 @@ func dispatchAgentMessage(ctx context.Context, c *Conn, hostID string, env api.E
|
||||
deps.OnScheduleFire(ctx, hostID, c, p.ScheduleID, p.ScheduledAt)
|
||||
}
|
||||
|
||||
case api.MsgRepoStats, api.MsgCommandResult:
|
||||
// TODO(P2): persist these projections.
|
||||
case api.MsgRepoStats:
|
||||
var p api.RepoStatsPayload
|
||||
if err := env.UnmarshalPayload(&p); err != nil {
|
||||
slog.Warn("ws: bad repo.stats payload", "host_id", hostID, "err", err)
|
||||
break
|
||||
}
|
||||
patch := store.HostRepoStats{
|
||||
HostID: hostID,
|
||||
TotalSizeBytes: p.TotalSizeBytes,
|
||||
RawSizeBytes: p.RawSizeBytes,
|
||||
UniqueFiles: p.UniqueFiles,
|
||||
SnapshotCount: p.SnapshotCount,
|
||||
LastCheckAt: p.LastCheckAt,
|
||||
LastCheckStatus: p.LastCheckStatus,
|
||||
LockPresent: p.LockPresent,
|
||||
LastPruneAt: p.LastPruneAt,
|
||||
LastPruneFreedBytes: p.LastPruneFreedBytes,
|
||||
}
|
||||
if err := deps.Store.UpsertHostRepoStats(ctx, hostID, patch); err != nil {
|
||||
slog.Warn("ws: upsert host repo stats", "host_id", hostID, "err", err)
|
||||
} else {
|
||||
slog.Info("ws: repo stats refreshed", "host_id", hostID)
|
||||
}
|
||||
|
||||
case api.MsgCommandResult:
|
||||
// TODO(P2): persist command.result acks for "did the agent
|
||||
// accept the dispatch?" forensics. Currently the job lifecycle
|
||||
// (job.started → job.finished) is sufficient signal.
|
||||
slog.Debug("ws msg not yet handled", "type", env.Type, "host_id", hostID)
|
||||
|
||||
case api.MsgError:
|
||||
|
||||
Reference in New Issue
Block a user