Overview
Risk Legion uses scheduled tasks for maintenance, cleanup, and automated processes. These can be configured via system cron, Docker, or external schedulers.Scheduled Tasks
Daily Tasks
| Task | Schedule | Description |
|---|---|---|
| Overdue Action Check | 00:00 UTC | Flag actions past due date |
| Metric Aggregation | 01:00 UTC | Pre-compute dashboard metrics |
| Log Rotation | 02:00 UTC | Archive old log files |
Weekly Tasks
| Task | Schedule | Description |
|---|---|---|
| Inactive User Report | Sunday 00:00 | Report users with no recent activity |
| Database Maintenance | Sunday 03:00 | VACUUM ANALYZE |
| Backup Verification | Sunday 04:00 | Verify backup integrity |
Monthly Tasks
| Task | Schedule | Description |
|---|---|---|
| Audit Log Archive | 1st 00:00 | Archive old audit logs |
| Usage Report | 1st 01:00 | Generate usage statistics |
Implementation
System Cron (EC2)
Docker-Based Cron
Using APScheduler
Task Scripts
Check Overdue Actions
Database Maintenance
Archive Audit Logs
External Schedulers
AWS EventBridge
For serverless scheduling:GitHub Actions Scheduled Workflow
Monitoring Cron Jobs
Logging
Health Checks
Use Cronitor or Healthchecks.io:Best Practices
Idempotency
Idempotency
- Jobs should be safe to run multiple times
- Use database transactions
- Check for already-processed items
Error Handling
Error Handling
- Catch and log exceptions
- Send alerts on failures
- Implement retry logic
Monitoring
Monitoring
- Log job start and completion
- Track job duration
- Alert on job failures
- Use dead man’s switch monitors
Resource Management
Resource Management
- Run heavy jobs during off-peak hours
- Batch large operations
- Set appropriate timeouts