Background Schedulers
MCP Server LangGraph includes two built-in schedulers for automated background tasks:- CleanupScheduler - Data retention enforcement (daily)
- ComplianceScheduler - SOC 2 compliance automation (daily/weekly/monthly)
CleanupScheduler
TheCleanupScheduler enforces data retention policies by automatically cleaning up expired data.
Features
- Daily execution at configurable time (default: 3 AM UTC)
- Configurable via
config/retention_policies.yaml - Dry-run mode for testing
- Metrics and alerting integration
- Graceful error handling
Configuration
Createconfig/retention_policies.yaml:
Usage
Cron Schedule Format
The cleanup schedule uses standard cron format:0 3 * * *- Daily at 3:00 AM0 */6 * * *- Every 6 hours0 3 * * 0- Weekly on Sunday at 3:00 AM
ComplianceScheduler
TheComplianceScheduler automates SOC 2 compliance tasks.
Scheduled Jobs
Features
- Automatic evidence collection
- Access review with recommendations
- Compliance scoring
- Alerting when score falls below threshold
- Report generation in JSON format
Usage
Access Review Report
The weekly access review generates anAccessReviewReport:
Alerting Thresholds
The compliance scheduler sends alerts based on:Environment Variables
Configure schedulers via environment variables:Monitoring
Metrics
Both schedulers emit OpenTelemetry metrics:Logs
Structured logs are emitted for all scheduler operations:Integration with FastAPI
Integrate schedulers with your FastAPI application lifecycle:Troubleshooting
Common Issues
Scheduler not running:- Check timezone configuration (default: UTC)
- Verify APScheduler job store persistence
- Review logs for execution errors
- Ensure jobs complete before next scheduled run
- Configure
max_instances=1to prevent overlapping