Skip to content

Commit e6bde1a

Browse files
committed
update/fix docs
1 parent 5b71f83 commit e6bde1a

File tree

6 files changed

+127
-71
lines changed

6 files changed

+127
-71
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ num = "0.4.3"
2222
num_cpus = "1.16.0"
2323
parking_lot = "0.12.3"
2424
paste = "1.0.15"
25+
simple-mermaid = "0.2.0"
2526
thiserror = "1.0.63"
2627
# required with the `affinity` feature
2728
core_affinity = { version = "0.8.1", optional = true }
@@ -37,6 +38,8 @@ itertools = "0.14.0"
3738
serial_test = "3.2.0"
3839
rstest = "0.22.0"
3940
stacker = "0.1.17"
41+
aquamarine = "0.6.0"
42+
simple-mermaid = "0.2.0"
4043

4144
[[bench]]
4245
name = "perf"

src/bee/mod.rs

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
//! A [`Hive`](crate::hive::Hive) is populated by bees:
44
//! * The [`Worker`]s process the tasks submitted to the `Hive`.
55
//! * The [`Queen`] creates a new `Worker` for each thread in the `Hive`.
6+
//! * [`QueenMut`] can be used to implement a stateful queen - it must be wrapped in a
7+
//! [`QueenCell`] to make it thread-safe.
8+
//!
9+
//! It is easiest to use the [`prelude`] when implementing your bees:
10+
//!
11+
//! ```
12+
//! use beekeeper::bee::prelude::*;
13+
//! ```
614
//!
715
//! # Worker
816
//!
@@ -18,7 +26,15 @@
1826
//!
1927
//! The `Worker` trait has a single method, [`apply`](crate::bee::Worker::apply), which
2028
//! takes an input of type `Input` and a [`Context`] and returns a `Result` containing an either an
21-
//! `Output` or an [`ApplyError`].
29+
//! `Output` or an [`ApplyError`]. Note that `Worker::apply()` takes a `&mut self` parameter,
30+
//! meaning that it can modify its own state.
31+
//!
32+
//! If a fatal error occurs during processing of the task, the worker should return
33+
//! [`ApplyError::Fatal`].
34+
//!
35+
//! If the task instead fails due to a transient error, the worker should return
36+
//! [`ApplyError::Retryable`]. If the `retry` feature is enabled, then a task that fails with a
37+
//! `ApplyError::Retryable` error will be retried, otherwise the error is converted to `Fatal`.
2238
//!
2339
//! The `Context` contains information about the task, including:
2440
//! * The task ID. Each task submitted to a `Hive` is assigned an ID that is unique within
@@ -29,16 +45,14 @@
2945
//! periodically check the cancellation flag by calling
3046
//! [`Context::is_cancelled()`](crate::bee::context::Context::is_cancelled). If the cancellation
3147
//! flag is set, the worker may terminate early by returning [`ApplyError::Cancelled`].
32-
//! * If the `retry` feature is enabled, the `Context` also contains the retry
33-
//! [`attempt`](crate::bee::context::Context::attempt), which starts at `0` the first time the task
34-
//! is attempted and increments by `1` for each subsequent retry attempt.
35-
//!
36-
//! If a fatal error occurs during processing of the task, the worker should return
37-
//! [`ApplyError::Fatal`].
48+
//! * The retry [`attempt`](crate::bee::context::Context::attempt), which starts at `0` the first
49+
//! time the task is attempted. If the `retry` feature is enabled and the task fails with
50+
//! [`ApplyError::Retryable], this value increments by `1` for each subsequent retry attempt.
3851
//!
39-
//! If the task instead fails due to a transient error, the worker should return
40-
//! [`ApplyError::Retryable`]. If the `retry` feature is enabled, then a task that fails with a
41-
//! `ApplyError::Retryable` error will be retried, otherwise the error is converted to `Fatal`.
52+
//! The `Context` also provides the ability to submit new tasks to the `Hive` using the
53+
//! [`submit`](crate::bee::Context::submit) method. The IDs of submitted subtasks are stored in the
54+
//! `Context` and are returned in a field of the [`Outcome`](crate::hive::Outcome) that results
55+
//! from the parent task.
4256
//!
4357
//! A `Worker` should not panic. However, if it must execute code that may panic, it can do so
4458
//! within a closure passed to [`Panic::try_call`](crate::panic::Panic::try_call) and convert an
@@ -85,25 +99,18 @@
8599
//! A queen is defined by implementing the [`Queen`] trait. A single `Queen` instance is used to
86100
//! create the `Worker` instances for each worker thread in a `Hive`.
87101
//!
88-
//! It is often not necessary to manually implement the `Queen` trait. For exmaple, if your `Worker`
102+
//! If you need for the queen to have mutable state, you can instead implement [`QueenMut`], whose
103+
//! [`create`](crate::bee::QueenMut::create) method takes `&mut self` as a parameter. When
104+
//! creating a `Hive`, the `QueenMut` must be wrapped in a [`QueenCell`] to make it thread-safe.
105+
//!
106+
//! It is often not necessary to manually implement the `Queen` trait. For example, if your `Worker`
89107
//! implements `Default`, then you can use [`DefaultQueen`] implicitly by calling
90108
//! [`OpenBuilder::with_worker_default`](crate::hive::OpenBuilder::with_worker_default). Similarly,
91109
//! if your `Worker` implements `Clone`, then you can use [`CloneQueen`]
92110
//! implicitly by calling [`OpenBuilder::with_worker`](crate::hive::OpenBuilder::with_worker).
93111
//!
94112
//! A `Queen` should never panic when creating `Worker`s.
95113
//!
96-
//! # Implementation Notes
97-
//!
98-
//! It is easiest to use the [`prelude`] when implementing your bees:
99-
//!
100-
//! ```
101-
//! use beekeeper::bee::prelude::*;
102-
//! ```
103-
//!
104-
//! Note that both `Queen::create()` and `Worker::apply()` receive `&mut self`, meaning that they
105-
//! can modify their own state.
106-
//!
107114
//! The state of a `Hive`'s `Queen` may be interrogated either
108115
//! [during](crate::hive::Hive::queen) or [after](crate::hive::Hive::try_into_husk) the
109116
//! life of the `Hive`. However, `Worker`s may never be accessed directly. Thus, it is often

src/hive/builder/mod.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@
77
//! * Fully-typed: builder that has type parameters for the `Worker`, `Queen`, and `TaskQueues`
88
//! types. This is the only builder with a `build` method to create a `Hive`.
99
//!
10-
//! Generic - Queue
11-
//! | /
12-
//! Bee /
13-
//! | /
14-
//! Full
15-
//!
16-
//! All builders implement the `BuilderConfig` trait, which provides methods to set configuration
10+
//! All builders implement the `Builder` trait, which provides methods to set configuration
1711
//! parameters. The configuration options available:
1812
//! * [`Builder::num_threads`]: number of worker threads that will be spawned by the built `Hive`.
1913
//! * [`Builder::with_default_num_threads`] will set `num_threads` to the global default value.
@@ -26,19 +20,25 @@
2620
//! [`std::thread`](https://doc.rust-lang.org/stable/std/thread/index.html#stack-size)
2721
//! documentation for details on the default stack size.
2822
//!
23+
//! The following configuration options are available when the `affinity` feature is enabled:
24+
//! * [`Builder::core_affinity`]: List of CPU core indices to which the threads should be pinned.
25+
//! * [`Builder::with_default_core_affinity`] will set the list to all CPU core indices, though
26+
//! only the first `num_threads` indices will be used.
27+
//!
28+
//! The following configuration options are available when the `local-batch` feature is enabled:
29+
//! * [`Builder::batch_limit`]: Maximum number of tasks that can queued by a worker.
30+
//! * [`Builder::weight_limit`]: Maximum "weight" of tasks that can be queued by a worker.
31+
//! * [`Builder::with_default_batch_limit`] and [`Builder::with_default_weight_limit`] set the
32+
//! local-batch options to the global defaults, while [`Builder::with_no_local_batching`]
33+
//! disables local-batching.
34+
//!
2935
//! The following configuration options are available when the `retry` feature is enabled:
3036
//! * [`Builder::max_retries`]: maximum number of times a `Worker` will retry an
3137
//! [`ApplyError::Retryable`](crate::bee::ApplyError#Retryable) before giving up.
3238
//! * [`Builder::retry_factor`]: [`Duration`](std::time::Duration) factor for exponential backoff
3339
//! when retrying an `ApplyError::Retryable` error.
3440
//! * [`Builder::with_default_max_retries`] and [`Builder::with_default_retry_factor`] set the
35-
//! retry options to the global defaults, while [`Builder::with_no_retries`] disabled retrying.
36-
//!
37-
//! The following configuration options are available when the `affinity` feature is enabled:
38-
//! * [`Builder::core_affinity`]: List of CPU core indices to which the threads should be pinned.
39-
//! * [`Builder::with_default_core_affinity`] will set the list to all CPU core indices, though
40-
//! only the first `num_threads` indices will be used.
41-
//!
41+
//! retry options to the global defaults, while [`Builder::with_no_retries`] disables retrying.
4242
mod bee;
4343
mod full;
4444
mod open;

src/hive/inner/builder.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ pub trait BuilderConfig {
77
}
88

99
/// Trait that provides `Builder` types with methods for setting configuration parameters.
10+
/// There are multiple `Builder` implementations. See the
11+
/// [module documentation](crate::hive::builder) for more details.
12+
///
13+
#[doc = simple_mermaid::mermaid!("diagram.mmd")]
1014
///
1115
/// This is a sealed trait, meaning it cannot be implemented outside of this crate.
1216
pub trait Builder: BuilderConfig + Sized {

0 commit comments

Comments
 (0)