Data Cleanup Scheduler
Automated daily cleanup of old records with configurable retention and scheduling.
Source: src/cleanup/
Permission: MANAGE_SYSTEM (mutations), VIEW_SYSTEM_HEALTH (stats)
Configuration
Settings stored in config/cleanup-schedule.json:
{
"hour": 3,
"minute": 0,
"retentionDays": 2
}
- Default schedule: Daily at 03:00
- Default retention: 2 days
- Settings persist to disk and survive restarts
API Endpoints
| Method | Endpoint | Description |
|---|---|---|
POST | /cleanup/trigger | Manual full cleanup |
POST | /cleanup/trigger/:collection | Cleanup specific collection |
GET | /cleanup/stats | Cleanup statistics |
POST | /cleanup/settings | Update schedule/retention |
GET | /cleanup/settings | Get current settings |
How It Works
- Startup: Reads config from disk, creates cron job via
SchedulerRegistry - Daily execution: Calculates cutoff date (
now - retentionDays), deletes old records - Per-collection: Targets time-series data (metrics, logs, telemetry history)
- Setting changes: Updates config file and reschedules the cron job dynamically
System Maintenance Service
Source: src/maintenance/system-maintenance.service.ts
Complements cleanup with integrity checks:
| Method | Description |
|---|---|
checkCollectionsIntegrity() | Lists all MongoDB collections with document counts |
checkWebsocketStatus() | Reports device online/stale status (5-min threshold) |
Related Modules
SystemHealthModule— Metric samples cleaned by retention policyTelemetryModule— Telemetry history subject to cleanup