Skip to main content

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

MethodEndpointDescription
POST/cleanup/triggerManual full cleanup
POST/cleanup/trigger/:collectionCleanup specific collection
GET/cleanup/statsCleanup statistics
POST/cleanup/settingsUpdate schedule/retention
GET/cleanup/settingsGet current settings

How It Works

  1. Startup: Reads config from disk, creates cron job via SchedulerRegistry
  2. Daily execution: Calculates cutoff date (now - retentionDays), deletes old records
  3. Per-collection: Targets time-series data (metrics, logs, telemetry history)
  4. 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:

MethodDescription
checkCollectionsIntegrity()Lists all MongoDB collections with document counts
checkWebsocketStatus()Reports device online/stale status (5-min threshold)
  • SystemHealthModule — Metric samples cleaned by retention policy
  • TelemetryModule — Telemetry history subject to cleanup