pub struct BatchWorker { /* private fields */ }Expand description
Batch worker state.
Manages batch assembly for a single shard.
Implementations§
Source§impl BatchWorker
impl BatchWorker
Sourcepub fn new(
shard_id: u16,
config: BatchConfig,
next_sequence_published: Arc<AtomicU64>,
producer_nonce: u64,
) -> Self
pub fn new( shard_id: u16, config: BatchConfig, next_sequence_published: Arc<AtomicU64>, producer_nonce: u64, ) -> Self
Create a new batch worker.
next_sequence_published is the bus-owned mirror of
next_sequence. Pass Arc::new(AtomicU64::new(0)) if the
caller doesn’t need to observe the post-exit sequence;
production paths share it with bus::remove_shard_internal.
producer_nonce is stamped on every produced Batch for
cross-process dedup. The bus passes its loaded nonce in;
tests can use any u64 (typically 0 or the per-process
default).
Sourcepub fn add_events(&mut self, events: Vec<InternalEvent>) -> Option<Batch>
pub fn add_events(&mut self, events: Vec<InternalEvent>) -> Option<Batch>
Add events to the current batch.
Returns a completed batch if thresholds are met, or None if more events are needed.
§Empty-input side effect
Passing an empty events vec is not a no-op. The
BatchWorker’s recv-timeout arm calls add_events(vec![])
specifically to drive a check_timeout round, which may
flush the in-memory current_batch if max_delay has
elapsed since the last event arrived. Callers who want
“true no-op on empty input” must check events.is_empty()
themselves before calling.
Pre-fix this side effect was not documented and
surprised callers expecting add_events([]) to be inert.
The fix is documentation only — the BatchWorker’s timeout
flush relies on this behavior, so removing the side effect
would break the timeout-flush mechanism in bus.rs.
Sourcepub fn has_pending(&self) -> bool
pub fn has_pending(&self) -> bool
Check if there are pending events.
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Get the number of pending events.
Sourcepub fn target_batch_size(&self) -> usize
pub fn target_batch_size(&self) -> usize
Get the current target batch size.
Sourcepub fn time_until_timeout(&self) -> Option<Duration>
pub fn time_until_timeout(&self) -> Option<Duration>
Get time until the current batch times out.