A robust, asynchronous task scheduling system built in Rust using Tokio. This scheduler provides a flexible framework for distributing and executing tasks across multiple workers, with support for both shell commands and file processing operations.
- Asynchronous Execution: Built on Tokio for efficient concurrent task processing
- Multiple Task Types: Support for shell commands and file processing operations
- Worker Management: Dynamic worker allocation and task distribution
- Status Tracking: Real-time task state monitoring and updates
- Cross-Platform: Compatible with both Windows and Unix-based systems
- Error Handling: Robust error management with detailed feedback
The system consists of four main components:
- Manages task distribution and worker coordination
- Maintains task and worker state
- Handles task submissions and updates
- Implements task queuing and scheduling logic
- Executes assigned tasks asynchronously
- Handles both shell commands and file operations
- Provides detailed execution feedback
- Implements error handling and recovery
- Represents individual work units
- Supports multiple command types
- Tracks execution state and progress
- Contains metadata like creation time and ID
- Defines core system types and states
- Implements error handling structures
- Provides common type definitions and enums
- Add the dependency to your
Cargo.toml:
[dependencies]
task-scheduler = { git = "https://github.com/Trojan-254/task-scheduler" }- Install required dependencies:
cargo builduse task_scheduler::{
task::{Task, TaskCommand},
types::WorkerId,
worker::Worker,
scheduler::Scheduler,
};
#[tokio::main]
async fn main() {
// Initialize the scheduler
let mut scheduler = Scheduler::new();
// Create a worker
let worker_id = WorkerId::from("worker1");
let command_rx = scheduler.add_worker(worker_id.clone()).await;
let worker = Worker::new(
worker_id,
command_rx,
scheduler.get_update_tx(),
);
// Spawn worker
tokio::spawn(async move {
worker.run().await;
});
// Create and submit a task
let task = Task::new(
"list-files".to_string(),
TaskCommand::Shell("ls -la".to_string()),
);
scheduler.submit_task(task).await;
// Handle updates
scheduler.handle_updates().await;
}- Shell Commands:
let shell_task = Task::new(
"memory-check".to_string(),
TaskCommand::Shell("free -h".to_string()),
);- File Processing:
let file_task = Task::new(
"read-log".to_string(),
TaskCommand::FileProcess("/var/log/system.log".to_string()),
);Tasks can be in one of four states:
Pending: Task has been submitted but not yet startedRunning: Task is currently being executedCompleted(String): Task completed successfully with outputFailed(String): Task failed with error message
The system implements a custom TaskError type that is thread-safe and provides detailed error information. All errors are properly propagated and handled throughout the execution chain.
-
Worker Management
- Create workers based on system resources
- Monitor worker health and restart if necessary
- Implement proper shutdown procedures
-
Task Submission
- Include meaningful task IDs
- Set appropriate timeouts
- Handle task dependencies if needed
-
Error Handling
- Always check task results
- Implement retry logic for transient failures
- Log errors appropriately
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Run the test suite:
cargo testRun with specific features:
cargo test --features "extended-logging"- No built-in task prioritization
- Limited retry mechanisms
- No persistent storage of task states
- Single-thread execution per worker
- Task priority queues
- Persistent task storage
- Worker load balancing
- Task dependency management
- Advanced scheduling policies
- Web interface for monitoring
- Metrics and telemetry
- Docker support
For issues and feature requests, please use the GitHub issue tracker.
