diff --git a/.gitignore b/.gitignore index 147e43c..0d5c162 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ Cargo.lock docs/content/docs/CHANGELOG.md docs/content/docs/README.md +.DS_Store diff --git a/README.md b/README.md index c7ec6f8..77e1d06 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,25 @@ Here are some of the Backie's key features: - Task timeout: Tasks are retried if they are not completed in time - Scheduling of tasks: Tasks can be scheduled to be executed at a specific time +## Task execution protocol + +The following diagram shows the protocol used to execute tasks: + +```mermaid +stateDiagram-v2 + [*] --> Ready + Ready --> Running: Task is picked up by a worker + Running --> Done: Task is finished + Running --> Failed: Task failed + Failed --> Ready: Task is retried + Failed --> [*]: Task is not retried anymore, max retries reached + Done --> [*] +``` + +When a task goes from `Running` to `Failed` it is retried. The number of retries is controlled by the +[`BackgroundTask::MAX_RETRIES`] attribute. The default implementation uses `3` retries. + + ## Safety This crate uses `#![forbid(unsafe_code)]` to ensure everything is implemented in 100% safe Rust. diff --git a/src/runnable.rs b/src/runnable.rs index e272a2e..71248f4 100644 --- a/src/runnable.rs +++ b/src/runnable.rs @@ -53,8 +53,8 @@ pub trait BackgroundTask: Serialize + DeserializeOwned + Sync + Send + 'static { /// Number of retries for tasks. /// - /// By default, it is set to 5. - const MAX_RETRIES: i32 = 5; + /// By default, it is set to 3. + const MAX_RETRIES: i32 = 3; /// The application data provided to this task at runtime. type AppData: Clone + Send + 'static;