pub struct PipelineAggregate { /* private fields */ }Expand description
§Managing Processing Operations
§Error Handling and Recovery
§Pipeline Configuration Updates
§Event Management
The aggregate generates domain events for all significant state changes:
PipelineCreated: When a new pipeline is createdPipelineUpdated: When pipeline configuration changesProcessingStarted: When file processing beginsProcessingCompleted: When processing finishes successfullyProcessingFailed: When processing encounters errors
§Concurrency and Thread Safety
The aggregate is designed for single-threaded access within a transaction boundary. Concurrent access should be managed through:
- Repository-level locking mechanisms
- Optimistic concurrency control using version numbers
- Event store transaction boundaries
- Application-level coordination
§Performance Considerations
- Memory Usage: Scales with number of active processing contexts
- Event Storage: Uncommitted events held in memory until persistence
- Validation Overhead: All operations include business rule validation
- Version Tracking: Minimal overhead for optimistic concurrency control
§Error Recovery
The aggregate provides robust error handling:
- Validation Errors: Prevent invalid state transitions
- Processing Failures: Tracked with detailed error information
- Event Application: Supports replay for crash recovery
- State Consistency: Maintains valid state even during failures
Implementations§
Source§impl PipelineAggregate
impl PipelineAggregate
Sourcepub fn new(pipeline: Pipeline) -> Result<Self, PipelineError>
pub fn new(pipeline: Pipeline) -> Result<Self, PipelineError>
Creates a new pipeline aggregate
Sourcepub fn from_events(events: Vec<PipelineEvent>) -> Result<Self, PipelineError>
pub fn from_events(events: Vec<PipelineEvent>) -> Result<Self, PipelineError>
Loads aggregate from events (event sourcing)
Sourcepub fn uncommitted_events(&self) -> &[PipelineEvent]
pub fn uncommitted_events(&self) -> &[PipelineEvent]
Gets uncommitted events
Sourcepub fn mark_events_as_committed(&mut self)
pub fn mark_events_as_committed(&mut self)
Marks events as committed
Sourcepub fn update_pipeline(
&mut self,
updated_pipeline: Pipeline,
) -> Result<(), PipelineError>
pub fn update_pipeline( &mut self, updated_pipeline: Pipeline, ) -> Result<(), PipelineError>
Updates the pipeline configuration
Sourcepub fn start_processing(
&mut self,
input_path: String,
output_path: String,
file_size: u64,
security_context: SecurityContext,
) -> Result<Uuid, PipelineError>
pub fn start_processing( &mut self, input_path: String, output_path: String, file_size: u64, security_context: SecurityContext, ) -> Result<Uuid, PipelineError>
Starts processing a file
Sourcepub fn complete_processing(
&mut self,
processing_id: Uuid,
metrics: ProcessingMetrics,
output_size: u64,
) -> Result<(), PipelineError>
pub fn complete_processing( &mut self, processing_id: Uuid, metrics: ProcessingMetrics, output_size: u64, ) -> Result<(), PipelineError>
Completes processing
Sourcepub fn fail_processing(
&mut self,
processing_id: Uuid,
error_message: String,
error_code: String,
stage_name: Option<String>,
partial_metrics: Option<ProcessingMetrics>,
) -> Result<(), PipelineError>
pub fn fail_processing( &mut self, processing_id: Uuid, error_message: String, error_code: String, stage_name: Option<String>, partial_metrics: Option<ProcessingMetrics>, ) -> Result<(), PipelineError>
Fails processing
Sourcepub fn active_processing_contexts(&self) -> &HashMap<Uuid, ProcessingContext>
pub fn active_processing_contexts(&self) -> &HashMap<Uuid, ProcessingContext>
Gets active processing contexts
Sourcepub fn get_processing_context(
&self,
processing_id: Uuid,
) -> Option<&ProcessingContext>
pub fn get_processing_context( &self, processing_id: Uuid, ) -> Option<&ProcessingContext>
Gets a specific processing context
Sourcepub fn update_processing_context(
&mut self,
processing_id: Uuid,
context: ProcessingContext,
) -> Result<(), PipelineError>
pub fn update_processing_context( &mut self, processing_id: Uuid, context: ProcessingContext, ) -> Result<(), PipelineError>
Updates a processing context
Sourcepub fn validate(&self) -> Result<(), PipelineError>
pub fn validate(&self) -> Result<(), PipelineError>
Validates the aggregate state
Sourcepub fn has_uncommitted_events(&self) -> bool
pub fn has_uncommitted_events(&self) -> bool
Checks if the aggregate has uncommitted events
Sourcepub fn active_processing_count(&self) -> usize
pub fn active_processing_count(&self) -> usize
Gets the number of active processing contexts
Sourcepub fn is_processing_active(&self) -> bool
pub fn is_processing_active(&self) -> bool
Checks if processing is active
Trait Implementations§
Source§impl Clone for PipelineAggregate
impl Clone for PipelineAggregate
Source§fn clone(&self) -> PipelineAggregate
fn clone(&self) -> PipelineAggregate
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for PipelineAggregate
impl RefUnwindSafe for PipelineAggregate
impl Send for PipelineAggregate
impl Sync for PipelineAggregate
impl Unpin for PipelineAggregate
impl UnwindSafe for PipelineAggregate
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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