feat(monitor): auto-prune expired maintenance windows
CI / test (pull_request) Successful in 2m33s
CI / lint (pull_request) Successful in 56s
CI / vulncheck (pull_request) Successful in 50s

Background goroutine runs every 15 minutes, deletes maintenance windows
that expired beyond the retention period (default 7 days). Configurable
via UPTOP_MAINT_RETENTION env var (Go duration format).

Closes #72
This commit was merged in pull request #96.
This commit is contained in:
2026-06-05 18:27:42 -04:00
parent 33dc84449b
commit 21a1563e53
9 changed files with 156 additions and 35 deletions
+12
View File
@@ -619,6 +619,18 @@ func (s *SQLStore) DeleteMaintenanceWindow(id int) error {
return nil
}
func (s *SQLStore) PruneExpiredMaintenanceWindows(retention time.Duration) (int64, error) {
cutoff := time.Now().Add(-retention)
result, err := s.db.Exec(
s.q("DELETE FROM maintenance_windows WHERE end_time IS NOT NULL AND end_time < ?"),
cutoff,
)
if err != nil {
return 0, err
}
return result.RowsAffected()
}
func (s *SQLStore) IsMonitorInMaintenance(monitorID int) (bool, error) {
var count int
err := s.db.QueryRow(s.q(`SELECT COUNT(*) FROM maintenance_windows