Expand description
An asynchronous task scheduling library written in Rust.
tasklet allows you to create scheduled tasks with specific execution patterns and
run them asynchronously using Tokio. It supports cron-like scheduling expressions and
provides a builder pattern for easy task creation.
§Highlights
- Async steps — every task step is a closure returning a future, so steps can
.awaitreal asynchronous work (I/O, timers, …) without blocking the runtime. - Graceful shutdown — obtain a [
scheduler::SchedulerHandle] viaTaskScheduler::handlebefore running and callshutdown()to stop the scheduler cleanly, or drive shutdown with any future viaTaskScheduler::run_until.
§Example
use tasklet::task::TaskStepStatusOk::Success;
use tasklet::{TaskBuilder, TaskScheduler};
#[tokio::main]
async fn main() {
let mut scheduler = TaskScheduler::default(chrono::Local);
let _ = scheduler.add_task(
TaskBuilder::new(chrono::Local)
.every("1 * * * * * *")
.description("A simple task")
.add_step("Step 1", || async { Ok(Success) })
.build(),
);
scheduler.run().await;
}Re-exports§
pub use errors::TaskError;pub use errors::TaskResult;pub use task::Task;
Modules§
Macros§
- scheduler_
log - Macro for consistent scheduler logging
- step_
log - Macro for consistent task step logging
- task_
log - Macro for consistent task-related logging
Structs§
- Task
Builder - Task builder function.
- Task
Generator - Task generation structure.
- Task
Scheduler - Task scheduler and executor.