ProcessingContext

Struct ProcessingContext 

Source
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 None rather 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

Source

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
Source

pub fn id(&self) -> &ProcessingContextId

Gets the unique identifier for this processing context

§Returns

Reference to the context’s unique identifier

Source

pub fn file_size(&self) -> u64

Gets the total size of the file being processed

§Returns

Total file size in bytes

Source

pub fn processed_bytes(&self) -> u64

Gets the number of bytes processed so far

§Returns

Number of bytes processed

Source

pub fn security_context(&self) -> &SecurityContext

Gets the security context for authorization and access control

§Returns

Reference to the security context

Source

pub fn metrics(&self) -> &ProcessingMetrics

Gets the current processing metrics

§Returns

Reference to the processing metrics

Source

pub fn chunk_size(&self) -> &ChunkSize

Gets the chunk size configuration for processing

§Returns

Reference to the chunk size configuration

Source

pub fn worker_count(&self) -> &WorkerCount

Gets the number of worker threads for parallel processing

§Returns

Reference to the worker count configuration

Source

pub fn metadata(&self) -> &HashMap<String, String>

Gets all custom metadata associated with this context

§Returns

Reference to the metadata HashMap

Source

pub fn stage_results(&self) -> &HashMap<String, String>

Gets all stage processing results

§Returns

Reference to the stage results HashMap

Source

pub fn update_processed_bytes(&mut self, bytes: u64)

Sets the total number of bytes processed

Replaces the current processed byte count with a new absolute value.

§Arguments
  • bytes - New total byte count
§Side Effects

Updates the updated_at timestamp

Source

pub fn add_processed_bytes(&mut self, bytes: u64)

Increments the processed byte count

Adds the specified number of bytes to the current processed total.

§Arguments
  • bytes - Number of additional bytes to add
§Side Effects

Updates the updated_at timestamp

Source

pub fn update_metrics(&mut self, metrics: ProcessingMetrics)

Updates the processing metrics with new values

§Arguments
  • metrics - New metrics to replace current metrics
§Side Effects

Updates the updated_at timestamp

Source

pub fn add_metadata(&mut self, key: String, value: String)

Adds or updates a metadata key-value pair

§Arguments
  • key - Metadata key
  • value - Metadata value
§Side Effects

Updates the updated_at timestamp

Source

pub fn get_metadata(&self, key: &str) -> Option<&String>

Retrieves a metadata value by key

§Arguments
  • key - Metadata key to look up
§Returns
  • Some(&String) - Value if key exists
  • None - If key not found
Source

pub fn add_stage_result(&mut self, stage_name: String, result: String)

Records the result of a processing stage

§Arguments
  • stage_name - Name of the stage
  • result - Processing result or status
§Side Effects

Updates the updated_at timestamp

Source

pub fn update_security_context(&mut self, security_context: SecurityContext)

Updates the security context

§Arguments
  • security_context - New security context
§Side Effects

Updates the updated_at timestamp

Source

pub fn progress_percentage(&self) -> f64

Calculates processing progress as a percentage

§Returns

Progress as a percentage (0.0 to 100.0)

§Examples
Source

pub fn is_complete(&self) -> bool

Checks if processing is complete

§Returns

true if all bytes have been processed, false otherwise

Source

pub fn created_at(&self) -> DateTime<Utc>

Gets the timestamp when this context was created

§Returns

UTC creation timestamp

Source

pub fn updated_at(&self) -> DateTime<Utc>

Gets the timestamp of the last update to this context

§Returns

UTC timestamp of last modification

Trait Implementations§

Source§

impl Clone for ProcessingContext

Source§

fn clone(&self) -> ProcessingContext

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ProcessingContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ProcessingContext

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ProcessingContext

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,