1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
//! Background jobs, task handlers, and worker runtime.
//!
//! For a full walkthrough with diagrams, see the [repository README](https://github.com/unified-field-dev/boson/blob/main/README.md).
//!
//! **Source of truth:** `cargo doc -p uf-boson --features mem,axum --open` — architecture, boot
//! workflows, and examples live on the public API items and module pages below.
//!
//! ## Cargo features
//!
//! This crate ships with **no default features** (`default = []`). Enable explicitly:
//!
//! - `mem` — in-memory `MemQueueBackend` for tests and local dev
//! - `sqlite` — `SqliteQueueBackend` persistence
//! - `postgres` — `PostgresQueueBackend` persistence
//! - `telemetry-console` — marker for console ops log ([`ConsoleOpsLog`] is always re-exported)
//! - `axum` — HTTP admin API (`boson_router`, `BosonState`)
//!
//! Fleet backends (`boson-backend-redis`, `boson-backend-nats`) are separate workspace crates.
//!
// Maintainer doc rules (not rendered in public docs):
// - Task docs: #[task], macro attrs, send_with — link to boot items instead of duplicating.
// - Boot docs: BosonBuilder, auto_registry, configure, backend, telemetry, axum — once per process.
// - Backend docs: QueueBackend trait, reference adapters — link to How to implement.
//!
//! # Getting started
//!
//! Depend on this crate with the `mem` feature, boot a worker, and hold a runtime handle:
//!
//! ```rust
//! # #[cfg(feature = "mem")]
//! # {
//! # use std::sync::Arc;
//! # use boson::{Boson, JsonExecutionContextFactory, MemQueueBackend};
//! let _boson = Boson::builder()
//! .queue_backend(Arc::new(MemQueueBackend::new()))
//! .execution_context_factory(JsonExecutionContextFactory)
//! .build_manual()
//! .expect("build");
//! # }
//! ```
//!
//! ## Documentation map
//!
//! Full snippets live on the linked items (not repeated here).
//!
//! - **Define a handler** — `#[task(name = "...")]` with typed params and `send_with`. Example on [`task`].
//! - **Boot a worker** — wire backend, identity factory, and task discovery once per process.
//! Examples on [`BosonBuilder`], [`BosonBuilder::auto_registry`], [`configure`].
//! - **Enqueue work** — `<TaskName>::send_with(actor_json, params)` or [`Boson::enqueue`].
//! - **Run jobs** — background worker via [`BosonBuilder::build`], or step-driven
//! [`ManualWorker::try_run_next`] for tests. Examples on each method.
//! - **Configure task policies** — retries, rate limits, pools via macro attributes or persisted
//! [`TaskConfig`]. Example on [`TaskConfig`].
//! - **Choose persistence** — `MemQueueBackend` (`mem`), `SqliteQueueBackend` (`sqlite`),
//! `PostgresQueueBackend` (`postgres`), or fleet crates
//! [`boson-backend-redis`](https://docs.rs/boson-backend-redis) /
//! [`boson-backend-nats`](https://docs.rs/boson-backend-nats). Connect examples on each backend type.
//! - **Mount HTTP admin** — nest `boson_router` at `/api/boson` ([`NEST_PATH`](https://docs.rs/uf-boson/latest/boson/constant.NEST_PATH.html) when `axum` is enabled). Runnable:
//! `cargo run -p uf-boson --example axum_admin --features mem,axum`.
//! - **Implement custom persistence** — honor the [`QueueBackend`] contract; start from
//! `MemQueueBackend` or see **How to implement** on the trait.
//!
//! Runnable binaries: `task_macro`, `minimal_enqueue`, `idempotency_and_rate_limit`, `axum_admin`
//! (`cargo run -p uf-boson --example <name> --features mem`).
//!
//! ## Configuration precedence
//!
//! | Layer | Resolution order |
//! |-------|------------------|
//! | Worker settings | [`BosonBuilder`] field → environment variable → hardcoded default |
//! | Task config at enqueue | Persisted backend config → macro/descriptor defaults |
//! | Idempotency mode | Per-task override → [`BosonBuilder::idempotency_mode`] (default lease-backed) |
//! | Queue backend | Explicit [`BosonBuilder::queue_backend`] → global router |
//! | Ops log | [`BosonBuilder::ops_log`] → [`NoOpsLog`]; or [`ops_log_from_env`] separately |
//! | Fleet URLs (Redis/NATS) | `BOSON_*_POOL_ROUTING` → `BOSON_*_URLS` |
//!
//! See [`WorkerSettings`] and [`TaskConfig`] for field-level defaults.
//!
//! ## Adding another task
//!
//! When the worker is already booted, adding a handler is only the macro and enqueue call:
//!
//! ```rust,no_run
//! use boson::{task, ExecutionContext};
//!
//! #[task(name = "notify")]
//! async fn notify(ctx: Box<dyn ExecutionContext>, message: String) -> boson_core::Result<()> {
//! let _ = (ctx, message);
//! Ok(())
//! }
//!
//! # async fn enqueue() -> boson_core::Result<()> {
//! Notify::send_with(
//! serde_json::json!({"System": {"operation": "notify"}}),
//! NotifyParams { message: "hello".into() },
//! )
//! .await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## First boot and first task
//!
//! ```rust,no_run
//! use std::sync::Arc;
//!
//! use boson::{
//! configure, task, Boson, ExecutionContext, JsonExecutionContextFactory,
//! };
//! # #[cfg(feature = "mem")]
//! # use boson::MemQueueBackend;
//!
//! #[task(name = "greet")]
//! async fn greet(ctx: Box<dyn ExecutionContext>, name: String) -> boson_core::Result<()> {
//! let _ = (ctx, name);
//! Ok(())
//! }
//!
//! # async fn run() -> boson_core::Result<()> {
//! # #[cfg(feature = "mem")]
//! # {
//! let boson = Boson::builder()
//! .queue_backend(Arc::new(MemQueueBackend::new()))
//! .execution_context_factory(JsonExecutionContextFactory)
//! .auto_registry()
//! .build()?;
//! configure(boson);
//! # }
//!
//! Greet::send_with(
//! serde_json::json!({"System": {"operation": "demo"}}),
//! GreetParams { name: "world".into() },
//! )
//! .await?;
//! # Ok(())
//! # }
//! ```
pub use ;
/// Background task handler — typed params, `send_with` enqueue, and link-time registration.
///
/// # Example
///
/// Assumes the worker is already booted; for one-time setup see
/// [First boot and first task](crate#first-boot-and-first-task).
///
/// ```rust,no_run
/// use boson::{task, ExecutionContext};
///
/// #[task(name = "notify")]
/// async fn notify(
/// ctx: Box<dyn ExecutionContext>,
/// message: String,
/// ) -> boson_core::Result<()> {
/// let _ = (ctx, message);
/// Ok(())
/// }
///
/// # async fn enqueue() -> boson_core::Result<()> {
/// Notify::send_with(
/// serde_json::json!({"System": {"operation": "notify"}}),
/// NotifyParams { message: "hello".into() },
/// )
/// .await?;
/// # Ok(())
/// # }
/// ```
///
/// # Contract
///
/// - Function must be `async`.
/// - First parameter must be `Box<dyn ExecutionContext>`.
/// - Return type must be `Result<()>` (typically `boson_core::Result<()>`).
/// - `name = "..."` is required and must be the first attribute.
///
/// # Policy attributes
///
/// Optional: `priority`, `pool`, `max_attempts`, `base_delay_ms`, `backoff_multiplier`,
/// `max_delay_ms`, `max_in_flight`, `max_enqueue_per_second`. Defaults and meanings are documented
/// on [`boson_macros`](https://docs.rs/boson-macros).
pub use task;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;