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
//! Small worker runtime primitives.
//!
//! Applications provide job acquisition and processing through [`Worker`].
//! Configuration, outbox processing, leasing, and loop orchestration live in
//! focused private modules and are re-exported as one feature-gated API.
//! Workers, batch jobs, outbox stores, and handlers can also be shared through
//! [`Arc`], including trait objects, without application-specific adapters.
//!
//! ```rust
//! use std::time::Duration;
//! use footing::worker::{BackoffConfig, RetryBackoff};
//!
//! let mut backoff = RetryBackoff::new(BackoffConfig::default());
//! assert_eq!(backoff.record_failure(), Duration::from_secs(1));
//! backoff.reset();
//! ```
//!
//! Queue jobs choose [`WorkerSchedule::Continue`] when another batch may be
//! ready, or [`WorkerSchedule::WaitForWork`] when idle. Ordinary workers keep
//! polling unless they explicitly choose a different schedule. Scheduling never
//! infers backlog from processed counts, and failure backoff cannot be woken.
//!
//! For the built-in outbox adapter, opt in with [`OutboxJob::with_queue_scheduling`]:
//!
//! ```no_run
//! use footing::worker::{
//! BatchWorker, OutboxHandler, OutboxItem, OutboxJob, OutboxStore,
//! ShutdownToken, WorkerConfig, WorkerRunError, WorkerRunOptions, WorkerWakeup,
//! run_worker_until_shutdown_with_options,
//! };
//!
//! async fn serve_queue<S, H, I>(
//! job: OutboxJob<S, H, I>,
//! wakeup: WorkerWakeup,
//! shutdown: ShutdownToken,
//! ) -> Result<(), WorkerRunError>
//! where
//! S: OutboxStore<I>,
//! H: OutboxHandler<I>,
//! I: OutboxItem,
//! {
//! // Enqueue producers retain a clone and call notify() after commit.
//! let options = WorkerRunOptions::new().with_wakeup(wakeup);
//! let worker = BatchWorker::new(job.with_queue_scheduling());
//! run_worker_until_shutdown_with_options(
//! worker, WorkerConfig::default(), shutdown, options,
//! ).await?;
//! Ok(())
//! }
//! ```
//!
//! Notifications are hints to check durable storage. Stores must enforce due
//! times and claims even when a notification arrives early. A new runner checks
//! the queue after its startup delay; idle polling also covers lost notifications
//! and retries outside the last batch. External listeners should subscribe before
//! checking existing work and repeat that check after reconnecting.
use ;
use async_trait;
pub use ;
pub use ;
pub use ;
pub use OutboxWorkerSettings;
pub use ;
pub use ;
pub use ;
/// Boxed worker errors used by the generic worker trait.
pub type BoxWorkerError = ;
/// Maximum supported worker name length.
pub const MAX_WORKER_NAME_LENGTH: usize = 128;
/// Maximum supported worker lease owner length.
pub const MAX_WORKER_LEASE_OWNER_LENGTH: usize = 128;
/// Execution metadata for one worker tick.
///
/// The fencing token is fixed for the entire tick, including lease renewals.
/// Applications must send it to protected resources, which must reject older
/// tokens. Merely receiving this context does not make effects exactly-once.
/// `Default` represents an execution without a runner lease.
/// One unit of repeatable background work.
///
/// Execution is at-least-once. A tick may be cancelled during shutdown or
/// repeated after an ambiguous failure or lease loss. Implementations must be
/// cancellation-safe and make externally visible effects idempotent. A worker
/// lease coordinates runners but cannot fence effects unless the application
/// propagates and enforces [`WorkerContext::fencing_token`] at the protected
/// resource. Shutdown drains an active tick within the configured timeout while
/// maintaining its lease; timeout or lease failure returns an error.
use ensure_worker_lease;