Crates.io | sisyphus-tasks |
lib.rs | sisyphus-tasks |
version | 0.1.1 |
source | src |
created_at | 2023-12-07 14:42:17.106091 |
updated_at | 2023-12-10 17:15:59.311071 |
description | Reusable utils for long-lived, worker-oriented rust programs |
homepage | |
repository | https://github.com/odyslam/sisyphus-tasks |
max_upload_size | |
id | 1061045 |
size | 69,225 |
Utilities for long-running, resilient tasks.
This library contains code I wrote, found useful, and want to keep using. It aims to provide systems
The general idiom is focused on spawning long-lived worker loops, which use channels to communicate.
pub struct MyWorker{
pipe: Pipe<WorkItem>,
}
impl Boulder for MyWorker {
fn spawn(self) -> JoinHandle<Fall<Self>> {
tokio::spawn(async move {
// pipe gives refs to items
while let Some(item) = self.pipe.next().await {
// worker does work on each item as it becomes available
self.do_work_on(item);
// do some async work too :)
self.async_work_as_well(item).await;
}
});
}
}
let task = MyWorker::new(a_pipe).run_forever();
Sisyphus
Boulder
is a looping, fallible taskBoulder
logic is defined in a Boulder::spawn()
method that returns a
JoinHandle
Fall
is an error in that task.
Fall::Recoverable
- errors that the task believes it can recoverFall::Unrecoverable
- errors that the task believes it cannot recoverBoulder::run_until_panic
method handles restarting on recoverable
Fall
s, and reporting unrecoverable errorsBoulder
s may define custom recovery or cleanup logicBoulder
s may also panic. In that case, no Fall
is generated, and the
Sisyphus
manages a Boulder
loop. He exposes an interface to observe its
status and abort the workPipe
for_each
on channel contentsT
, outbound U
)Some code descends from utilities written for Nomad. It is used and reproduced under its license terms.