Cronline
Cronline is a minimalist yet powerful cron-style task scheduler built with Rust. Designed for simplicity, performance, and ease of integration, Cronline enables developers to effortlessly manage scheduled asynchronous tasks within Rust applications.
Purpose
Cronline addresses the common need among Rust developers for reliable task scheduling without the overhead of external cron utilities or complex frameworks. It's ideal for:
- Web services
- Automation tools
- Background job management
- Bots
- Microservices
Core Features
- Cron-like Scheduling: Intuitive scheduling using cron syntax (
0 0 * * *) - Interval-based Scheduling: Simple interval-based task execution with
Task::with_interval() - Async-Await Native: First-class async task support leveraging Tokio
- Task Tags/Labels: Organize and filter tasks using tags
- Graceful Cancellation: Cancel running tasks cleanly
- Timeout Warnings: Get warned at 80% of timeout duration
- Event Bus: Subscribe to scheduler and task lifecycle events
- Auto-generated Names: Meaningful task names automatically generated from cron expressions
- Robust Logging: Built-in logging integration (
log,env_logger, ortracing) - Fault-Tolerance & Retries: Configurable error handling and automatic task retries
- Simple & Modular: Easy to include and extend in existing Rust codebases
Installation
Add Cronline to your Cargo.toml:
[]
= "0.2.1"
Basic Usage
use ;
use tokio;
async
Advanced Usage
use ;
use Duration;
async
Enhanced Features
Interval-based Scheduling
// Create a task that runs every 5 minutes
let task = new
.with_interval;
scheduler.add_task.await?;
Task Tags and Filtering
// Create tasks with tags
let backup_task = new
.with_tags;
let monitoring_task = new
.with_tag;
scheduler.add_task?;
scheduler.add_task?;
// Filter tasks by tags
let critical_tasks = scheduler.tasks_with_tag.await;
let backup_or_monitoring = scheduler.tasks_with_any_tag.await;
let critical_backups = scheduler.tasks_with_all_tags.await;
Event Bus
// Subscribe to scheduler events
let mut events = scheduler.event_bus.subscribe;
spawn;
Task Cancellation
// Cancel a running task
if let Some = scheduler.get_task.await
Auto-generated Task Names
// Task names are automatically generated from cron expressions
let task = new
.with_schedule?; // Automatically named "Hourly"
let task = new
.with_schedule?; // Automatically named "Every 5 Minutes"
let task = new
.with_interval; // Automatically named "Every 5 Minutes"
Task Management
// Get a list of all task IDs
let task_ids = scheduler.task_ids.await;
// Get a reference to a specific task
if let Some = scheduler.get_task.await
// Remove a task from the scheduler
scheduler.remove.unwrap;
Cron Expression Syntax
Cronline uses standard cron syntax: * * * * * (minute, hour, day of month, month, day of week)
Examples:
* * * * *- Every minute0 * * * *- Every hour at minute 00 0 * * *- Every day at midnight0 12 * * MON-FRI- Weekdays at noon*/15 * * * *- Every 15 minutes
Real-World Examples
Cronline includes comprehensive real-world examples demonstrating production patterns:
- Web Integration - Axum web framework integration with background tasks
- Monitoring & Alerting - System monitoring with threshold-based alerts
- Database Maintenance - Automated backups, optimization, and cleanup
- API Polling - Rate-limited API polling and web scraping
- Notifications - Email campaigns, reminders, and multi-channel messaging
- Cache Warming - Proactive cache management and optimization
See EXAMPLES.md for detailed documentation of all examples.
Run any example with:
Recent Enhancements (v0.1.1)
- ✅ Interval-based scheduling with
Task::with_interval(Duration) - ✅ Task tags/labels for grouping and filtering
- ✅ Graceful task cancellation
- ✅ Task timeout warnings at 80% of timeout
- ✅ Scheduler event bus for task/scheduler events
- ✅ Auto-generated meaningful names from cron expressions
Future Enhancements
- Task persistence with databases (SQLite, Redis)
- Interactive CLI for task management
- Web dashboard integration
- Task dependencies and workflows
- Distributed task scheduling
License
This project is licensed under the MIT License - see the LICENSE file for details.