Files
silo-server/internal/taskmanager/tasks/cleanup_client_diagnostics.go
T
Quick104andClaude Fable 5 4fa84a661a feat(diagnostics): client diagnostics server foundation
Implements slice 1 of docs/design/2026-07-19-client-diagnostics.md: the
versioned contract (schemas, fixtures, Go validator), storage-validated
diagnostics.uploads_enabled gate, account-scoped status endpoint, hardened
streaming multipart ingest with quota reservation and a receiving/ready/
failed report state machine, S3 streaming puts, acting-admin report API
(list/detail/download/delete with audit events), and the retention +
orphan-reconciliation cleanup task.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XppCCycoaskCsW7ja1fZct
2026-07-20 11:13:52 -04:00

71 lines
2.1 KiB
Go

package tasks
import (
"context"
"fmt"
"log/slog"
"time"
"github.com/Silo-Server/silo-server/internal/diagnostics"
"github.com/Silo-Server/silo-server/internal/opslog"
"github.com/Silo-Server/silo-server/internal/taskmanager"
)
// ClientDiagnosticsCleanupTask prunes expired client diagnostics and reconciles
// object-store leftovers from interrupted uploads.
type ClientDiagnosticsCleanupTask struct {
repo diagnostics.CleanupRepository
settings diagnostics.SettingsStore
store diagnostics.ObjectStore
logger *slog.Logger
}
func NewClientDiagnosticsCleanupTask(
repo diagnostics.CleanupRepository,
settings diagnostics.SettingsStore,
store diagnostics.ObjectStore,
) *ClientDiagnosticsCleanupTask {
return &ClientDiagnosticsCleanupTask{
repo: repo,
settings: settings,
store: store,
logger: slog.Default(),
}
}
func (t *ClientDiagnosticsCleanupTask) Key() string { return "cleanup_client_diagnostics" }
func (t *ClientDiagnosticsCleanupTask) Name() string {
return "Cleanup Client Diagnostics"
}
func (t *ClientDiagnosticsCleanupTask) Description() string {
return "Prunes expired client diagnostic reports and orphaned bundles"
}
func (t *ClientDiagnosticsCleanupTask) Category() taskmanager.TaskCategory {
return taskmanager.TaskCategorySystem
}
func (t *ClientDiagnosticsCleanupTask) IsHidden() bool { return false }
func (t *ClientDiagnosticsCleanupTask) DefaultTriggers() []taskmanager.TriggerConfig {
return []taskmanager.TriggerConfig{
{Type: taskmanager.TriggerTypeStartup},
{
Type: taskmanager.TriggerTypeInterval,
IntervalMs: int64(opslog.LoadCleanupInterval(context.Background(), t.settings) / time.Millisecond),
},
}
}
func (t *ClientDiagnosticsCleanupTask) Execute(ctx context.Context, progress taskmanager.ProgressReporter) error {
progress.Report(0, "Pruning client diagnostic reports")
result, err := diagnostics.CleanupOnce(ctx, t.repo, t.settings, t.store, t.logger)
if err != nil {
return err
}
progress.Report(100, fmt.Sprintf(
"Pruned %d client diagnostic reports and %d orphaned bundles",
result.ReportsDeleted(),
result.OrphanObjectsDeleted,
))
return nil
}