Problem#
Garbage collection only runs when manually triggered via POST /admin/gc. There is no way to schedule periodic automatic GC, meaning unreferenced blobs accumulate until an admin remembers to trigger cleanup.
Proposed Solution#
- Add a
--gc-intervalCLI argument (e.g.,--gc-interval 24h) - Spawn a background tokio task that runs GC on the configured interval
- Use the existing
gc::run_gc()function with configurable dry-run and grace period - Log GC results and expose last-GC metrics (timestamp, blobs freed, bytes freed)
- Add
grain_gc_last_run_timestampandgrain_gc_bytes_freed_totalPrometheus gauges/counters - Keep the manual
POST /admin/gcendpoint for on-demand runs
Files to modify#
src/main.rs- Spawn background GC tasksrc/args.rs- Add--gc-intervaland--gc-grace-periodargssrc/metrics.rs- Add GC metrics