Skip to main content

Background Schedulers

MCP Server LangGraph includes two built-in schedulers for automated background tasks:
  1. CleanupScheduler - Data retention enforcement (daily)
  2. ComplianceScheduler - SOC 2 compliance automation (daily/weekly/monthly)
Both schedulers use APScheduler for cron-based job scheduling.

CleanupScheduler

The CleanupScheduler 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

Create config/retention_policies.yaml:

Usage

Cron Schedule Format

The cleanup schedule uses standard cron format:
Examples:
  • 0 3 * * * - Daily at 3:00 AM
  • 0 */6 * * * - Every 6 hours
  • 0 3 * * 0 - Weekly on Sunday at 3:00 AM

ComplianceScheduler

The ComplianceScheduler 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 an AccessReviewReport:

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:
Missed jobs:
  • Check timezone configuration (default: UTC)
  • Verify APScheduler job store persistence
  • Review logs for execution errors
High memory usage:
  • Ensure jobs complete before next scheduled run
  • Configure max_instances=1 to prevent overlapping

Debug Mode

Enable debug logging: