task-supervisor-0.1.0 has been yanked.
🤖 task-supervisor
The task-supervisor
crate is a Rust library for managing and monitoring asynchronous tasks within the Tokio runtime. It ensures tasks remain operational by tracking their health via heartbeats and restarting them if they fail or become unresponsive.
It is really smol and simple for now.
Installation
Add the crate to your Cargo.toml
:
[]
= "0.1.0" # Replace with the latest version
= { = "1", = ["full"] }
= "0.1"
Usage
1. Defining a Supervised Task
Tasks must implement the SupervisedTask
trait, which requires an error type and the run_forever method:
use SupervisedTask;
use async_trait;
use Duration;
;
2. Setting Up and Running the Supervisor
Use the SupervisorBuilder
to create a supervisor and start supervising tasks:
use SupervisorBuilder;
async
The supervisor will:
- Start all tasks, each running its run_forever logic.
- Send heartbeats every second to confirm task health.
- Restart tasks that fail or miss heartbeats.
3. Checking Task Status
Retrieve the status of all tasks at any time:
let statuses = supervisor.task_statuses;
for in statuses
Statuses include Created
, Starting
, Healthy
, Failed
, and Dead
.
Contributing
Contributions are welcomed! Please:
- Fork the repository on GitHub.
- Submit a pull request with your changes or open an issue for discussion.
License
This crate is licensed under the MIT License. See the LICENSE file for details.