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
SchedulerHandleviaTaskScheduler::handlebefore running and callshutdown()to stop the scheduler cleanly, or drive shutdown with any future viaTaskScheduler::run_until. - Resilience — configure a per-step
TaskBuilder::timeout, aRetryPolicyviaTaskBuilder::retry, and async lifecycle callbacks (TaskBuilder::on_success/on_failure/on_finish).
§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 retry::Backoff;pub use retry::RetryPolicy;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§
- Scheduler
Handle - A cloneable handle used to control a running
TaskScheduler. - Task
Builder - Task builder function.
- Task
Generator - Task generation structure.
- Task
Scheduler - Task scheduler and executor.