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
| Job | Schedule | Description |
|---|---|---|
| Daily Compliance Check | 6:00 AM UTC | Collects evidence for all SOC 2 controls |
| Weekly Access Review | Monday 9:00 AM UTC | Reviews user access and identifies inactive accounts |
| Monthly Compliance Report | 1st of month, 9:00 AM UTC | Generates comprehensive SOC 2 report |
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:| Condition | Severity | Action |
|---|---|---|
| Compliance score < 80% | HIGH | Immediate review required |
| Job execution failure | CRITICAL | On-call notification |
| Access review findings | INFO | Security team notification |
Environment Variables
Configure schedulers via environment variables:| Variable | Default | Description |
|---|---|---|
COMPLIANCE_SCHEDULER_ENABLED | true | Enable/disable compliance scheduler |
CLEANUP_SCHEDULE | 0 3 * * * | Cron schedule for cleanup |
EVIDENCE_DIR | evidence/ | Directory for evidence files |
RETENTION_CONFIG_PATH | config/retention_policies.yaml | Retention config path |
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