pub struct ProcessingContext { /* private fields */ }Expand description
Processing context entity that maintains runtime state during pipeline execution.
The ProcessingContext serves as a central state container that travels
through the pipeline, collecting information and tracking progress as each
stage processes the data. It provides a unified interface for accessing and
updating processing state across all pipeline stages.
§Entity Purpose
- State Coordination: Centralizes processing state across pipeline stages
- Progress Tracking: Monitors processing progress and completion status
- Configuration Management: Maintains processing parameters and settings
- Metrics Collection: Aggregates performance and operational metrics
- Security Enforcement: Preserves security context throughout processing
§Usage Examples
§Creating a Processing Context
§Tracking Processing Progress
§Managing Stage Results
§Adding Custom Metadata
§Updating Processing Metrics
§State Lifecycle
The processing context follows a predictable lifecycle:
§1. Initialization
§2. Processing Updates
§3. Completion
§Thread Safety and Concurrency
While the context itself is not thread-safe, it’s designed for safe concurrent patterns:
§Serialization and Persistence
The context supports serialization for checkpointing and recovery:
§Performance Considerations
- Context updates are lightweight and fast
- Metadata and stage results use efficient HashMap storage
- Progress calculations are performed on-demand
- Timestamps are updated only when state changes
- Memory usage scales with the amount of stored metadata
§Error Handling
The context provides safe access to all state with appropriate defaults:
- Missing metadata returns
Nonerather than panicking - Progress calculations handle edge cases (zero file size)
- All numeric operations are checked for overflow
- Timestamp operations are guaranteed to succeed
Implementations§
Source§impl ProcessingContext
impl ProcessingContext
Sourcepub fn new(file_size: u64, security_context: SecurityContext) -> Self
pub fn new(file_size: u64, security_context: SecurityContext) -> Self
Creates a new processing context for pipeline execution
Initializes a chunk-scoped context with default configuration values and empty state. The context starts with zero processed bytes and will track progress and metadata as the chunk flows through pipeline stages.
§Design Note
This context is chunk-scoped, not file-scoped. File paths are managed
by the pipeline worker (via CpuWorkerContext) using dependency injection.
This separation ensures the context focuses on chunk processing metadata
without coupling to file I/O concerns.
§Arguments
file_size- Total size of the file being processed (for progress tracking)security_context- Security context for authorization and access control
§Returns
A new ProcessingContext with initialized state
§Examples
Sourcepub fn id(&self) -> &ProcessingContextId
pub fn id(&self) -> &ProcessingContextId
Gets the unique identifier for this processing context
§Returns
Reference to the context’s unique identifier
Sourcepub fn processed_bytes(&self) -> u64
pub fn processed_bytes(&self) -> u64
Sourcepub fn security_context(&self) -> &SecurityContext
pub fn security_context(&self) -> &SecurityContext
Gets the security context for authorization and access control
§Returns
Reference to the security context
Sourcepub fn metrics(&self) -> &ProcessingMetrics
pub fn metrics(&self) -> &ProcessingMetrics
Sourcepub fn chunk_size(&self) -> &ChunkSize
pub fn chunk_size(&self) -> &ChunkSize
Sourcepub fn worker_count(&self) -> &WorkerCount
pub fn worker_count(&self) -> &WorkerCount
Gets the number of worker threads for parallel processing
§Returns
Reference to the worker count configuration
Sourcepub fn stage_results(&self) -> &HashMap<String, String>
pub fn stage_results(&self) -> &HashMap<String, String>
Sourcepub fn update_processed_bytes(&mut self, bytes: u64)
pub fn update_processed_bytes(&mut self, bytes: u64)
Sourcepub fn add_processed_bytes(&mut self, bytes: u64)
pub fn add_processed_bytes(&mut self, bytes: u64)
Sourcepub fn update_metrics(&mut self, metrics: ProcessingMetrics)
pub fn update_metrics(&mut self, metrics: ProcessingMetrics)
Sourcepub fn add_metadata(&mut self, key: String, value: String)
pub fn add_metadata(&mut self, key: String, value: String)
Sourcepub fn get_metadata(&self, key: &str) -> Option<&String>
pub fn get_metadata(&self, key: &str) -> Option<&String>
Sourcepub fn add_stage_result(&mut self, stage_name: String, result: String)
pub fn add_stage_result(&mut self, stage_name: String, result: String)
Sourcepub fn update_security_context(&mut self, security_context: SecurityContext)
pub fn update_security_context(&mut self, security_context: SecurityContext)
Sourcepub fn progress_percentage(&self) -> f64
pub fn progress_percentage(&self) -> f64
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Sourcepub fn created_at(&self) -> DateTime<Utc>
pub fn created_at(&self) -> DateTime<Utc>
Sourcepub fn updated_at(&self) -> DateTime<Utc>
pub fn updated_at(&self) -> DateTime<Utc>
Trait Implementations§
Source§impl Clone for ProcessingContext
impl Clone for ProcessingContext
Source§fn clone(&self) -> ProcessingContext
fn clone(&self) -> ProcessingContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ProcessingContext
impl Debug for ProcessingContext
Source§impl<'de> Deserialize<'de> for ProcessingContext
impl<'de> Deserialize<'de> for ProcessingContext
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for ProcessingContext
impl RefUnwindSafe for ProcessingContext
impl Send for ProcessingContext
impl Sync for ProcessingContext
impl Unpin for ProcessingContext
impl UnwindSafe for ProcessingContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more