Scheduler Cron Integration
Description
The Scheduler Cron Integration skill provides scheduled execution capabilities for recurring operations such as daily summaries and weekly audits. This skill enables Claude Code to automatically execute tasks at specified intervals using cron-like expressions and provides a comprehensive task scheduling system.
Purpose
This skill implements robust scheduling functionality to:
- Execute recurring operations automatically (daily, weekly, monthly)
- Support cron-like expressions for flexible scheduling
- Manage job lifecycles and execution states
- Provide monitoring and logging for scheduled tasks
- Enable automated reporting and maintenance operations
- Support both system-level and user-defined schedules
Key Features
Cron Expression Support
- Standard cron expression parsing (* * * * *)
- Extended cron features (seconds, named months/days)
- Predefined schedules (@hourly, @daily, @weekly, @monthly, @yearly)
- Complex interval specifications
Job Management
- Create, update, delete scheduled jobs
- Job persistence across restarts
- Execution history and logging
- Job status monitoring (running, paused, completed)
- Error handling and retry mechanisms
Schedule Types
- Time-based scheduling (minute, hour, day, month, weekday)
- Interval-based scheduling (every N minutes/hours/days)
- Fixed-point scheduling (specific dates/times)
- Conditional scheduling (based on system conditions)
Execution Engine
- Concurrent job execution
- Resource management and load balancing
- Execution context isolation
- Timeout and cancellation support
- Parallel and sequential execution modes
Configuration
Default Configuration
{
"scheduler": {
"enabled": true,
"max_concurrent_jobs": 10,
"job_storage_path": "./scheduled_jobs",
"log_retention_days": 30,
"check_interval_seconds": 30
},
"cron": {
"support_seconds": true,
"timezone": "UTC",
"max_execution_time_minutes": 60
},
"jobs": {
"default_timeout_minutes": 10,
"max_retries": 3,
"retry_delay_seconds": 30
}
}
Example Job Definitions
[
{
"id": "daily_summary",
"name": "Daily Summary Report",
"cron_expression": "0 9 * * *", // Every day at 9 AM
"command": "generate_daily_summary",
"enabled": true,
"description": "Generates daily summary report"
},
{
"id": "weekly_audit",
"name": "Weekly Security Audit",
"cron_expression": "0 2 * * 0", // Every Sunday at 2 AM
"command": "perform_security_audit",
"enabled": true,
"description": "Performs weekly security audit"
},
{
"id": "monthly_cleanup",
"name": "Monthly Cleanup",
"cron_expression": "0 1 1 * *", // First day of every month at 1 AM
"command": "cleanup_old_files",
"enabled": true,
"description": "Cleans up old temporary files"
}
]
Usage Scenarios
Basic Job Scheduling
from scheduler_cron_integration import Scheduler
scheduler = Scheduler()
job_id = scheduler.schedule_job(
name="daily_backup",
cron_expression="0 2 * * *", # Daily at 2 AM
callback_function=backup_function,
args=[param1, param2],
description="Daily backup operation"
)
Dynamic Job Management
# Pause a job
scheduler.pause_job("daily_backup")
# Resume a job
scheduler.resume_job("daily_backup")
# Update job schedule
scheduler.update_job_schedule("daily_backup", "0 3 * * *") # Move to 3 AM
# Cancel a job
scheduler.cancel_job("daily_backup")
Job Status and Monitoring
# Get job status
status = scheduler.get_job_status("daily_backup")
print(f"Next run: {status.next_run}")
print(f"Last run: {status.last_run}")
print(f"Execution count: {status.execution_count}")
# Get execution history
history = scheduler.get_job_history("daily_backup", limit=10)
for record in history:
print(f"Run at {record.timestamp}: {record.status} ({record.duration}s)")
Integration Points
With Claude Code
- Trigger scheduled operations through Claude commands
- Integrate with existing tool execution framework
- Support for scheduled file operations
- Automatic execution of maintenance tasks
With External Systems
- API call scheduling
- Database operation scheduling
- File system operation scheduling
- Third-party service integration
Error Handling
Execution Failures
- Automatic retry with exponential backoff
- Detailed error logging and reporting
- Failure notification mechanisms
- Recovery strategies
System Issues
- Graceful degradation when resources are low
- Proper cleanup of failed executions
- Persistent state management
- Restart recovery capabilities
Security Considerations
- Secure execution context for scheduled tasks
- Permission checking for scheduled operations
- Audit logging for all scheduled activities
- Protection against infinite loops/cascading failures
Performance Considerations
- Efficient cron expression evaluation
- Minimal resource overhead for scheduler
- Scalable job management
- Optimized storage for job definitions
Dependencies
croniterfor cron expression parsingapschedulerfor advanced scheduling featurespytzfor timezone handlingsqlite3for job persistence (optional)structlogfor structured logging
When NOT to Use This Skill
- Event-driven tasks — if tasks should trigger on external events (webhooks, message queue messages), use
event-streaminginstead of a time-based scheduler - Sub-minute scheduling — cron-based schedulers have a 1-minute minimum interval; for sub-minute tasks, use an application-level timer or a message queue consumer
- Distributed job scheduling across multiple nodes — single-node cron can't coordinate job execution across a cluster; use a distributed scheduler (Celery Beat, Airflow) for multi-node environments
Common Mistakes
- Not implementing job locking — cron jobs that take longer than their interval can overlap with the next execution; always implement a distributed lock to prevent concurrent runs
- Writing scheduled jobs that swallow errors silently — cron doesn't retry failed jobs by default; implement explicit failure logging and alerting so missed executions are visible
- Not testing cron expressions before deploying — off-by-one errors in cron syntax (
0 8 * * 1vs0 8 * * 0) schedule jobs on the wrong day or time; always validate expressions