Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

perf: skip initial patrol if one ran recently

rcourtman8ee315eee4b7
diff --git a/internal/ai/patrol.go b/internal/ai/patrol.go
index b363c50158..911d917c34 100644
--- a/internal/ai/patrol.go
+++ b/internal/ai/patrol.go
@@ -641,11 +641,28 @@ func (p *PatrolService) Stop() {
// patrolLoop is the main background loop
func (p *PatrolService) patrolLoop(ctx context.Context) {
- // Run initial quick patrol shortly after startup
+ // Run initial patrol shortly after startup, but only if one hasn't run recently
initialDelay := 30 * time.Second
select {
case <-time.After(initialDelay):
- p.runPatrol(ctx)
+ // Check if a patrol ran recently (within last hour) to avoid wasting tokens on restarts
+ runHistory := p.GetRunHistory(1)
+
+ skipInitial := false
+ if len(runHistory) > 0 {
+ lastRun := runHistory[0]
+ timeSinceLastRun := time.Since(lastRun.CompletedAt)
+ if timeSinceLastRun < 1*time.Hour {
+ log.Info().
+ Dur("time_since_last", timeSinceLastRun).
+ Msg("AI Patrol: Skipping initial patrol - recent run exists")
+ skipInitial = true
+ }
+ }
+
+ if !skipInitial {
+ p.runPatrol(ctx)
+ }
case <-p.stopCh:
return
case <-ctx.Done():