pub struct SerializedTask {
pub metadata: TaskMetadata,
pub payload: Vec<u8>,
}Expand description
Serialized task ready for queue
§Zero-Copy Serialization Considerations
The current implementation uses Vec<u8> for the payload, which requires
copying data during serialization and deserialization. For high-performance
scenarios, consider these alternatives:
-
Bytesfrombytescrate: Provides cheap cloning via reference countingⓘuse bytes::Bytes; pub payload: Bytes, -
Arc<[u8]>: Reference-counted slice for shared ownershipⓘuse std::sync::Arc; pub payload: Arc<[u8]>, -
Borrowed payloads with lifetimes: For truly zero-copy deserialization
ⓘ#[derive(Deserialize)] pub struct SerializedTask<'a> { #[serde(borrow)] pub payload: &'a [u8], }
Trade-offs:
Vec<u8>: Simple, owned data, but requires copyingBytes: Cheap cloning, but requires external dependencyArc<[u8]>: Cheap cloning, but atomic operations have overhead- Borrowed: True zero-copy, but lifetime complexity and limited use cases
For most use cases, the current Vec<u8> approach provides a good balance
of simplicity and performance. Consider alternatives only when profiling shows
serialization as a bottleneck.
Fields§
§metadata: TaskMetadataTask metadata
payload: Vec<u8>Serialized task payload
Implementations§
Source§impl SerializedTask
impl SerializedTask
pub fn new(name: String, payload: Vec<u8>) -> Self
pub fn with_priority(self, priority: i32) -> Self
pub fn with_max_retries(self, max_retries: u32) -> Self
pub fn with_timeout(self, timeout_secs: u64) -> Self
Sourcepub fn with_group_id(self, group_id: Uuid) -> Self
pub fn with_group_id(self, group_id: Uuid) -> Self
Set the group ID for workflow grouping
Sourcepub fn with_chord_id(self, chord_id: Uuid) -> Self
pub fn with_chord_id(self, chord_id: Uuid) -> Self
Set the chord ID for barrier synchronization
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Check if the task has expired based on its timeout
Sourcepub fn is_terminal(&self) -> bool
pub fn is_terminal(&self) -> bool
Check if the task is in a terminal state (Success or Failure)
Sourcepub fn validate(&self) -> Result<(), String>
pub fn validate(&self) -> Result<(), String>
Validate the serialized task
Validates both metadata and payload constraints:
- Delegates metadata validation to
TaskMetadata::validate() - Checks payload size (must be < 1MB by default)
§Errors
Returns an error if validation fails.
Sourcepub fn has_timeout(&self) -> bool
pub fn has_timeout(&self) -> bool
Check if task has a timeout configured
Sourcepub fn has_group_id(&self) -> bool
pub fn has_group_id(&self) -> bool
Check if task is part of a group
Sourcepub fn has_chord_id(&self) -> bool
pub fn has_chord_id(&self) -> bool
Check if task is part of a chord
Sourcepub fn has_priority(&self) -> bool
pub fn has_priority(&self) -> bool
Check if task has custom priority (non-zero)
Sourcepub const fn payload_size(&self) -> usize
pub const fn payload_size(&self) -> usize
Get payload size in bytes
Sourcepub fn has_empty_payload(&self) -> bool
pub fn has_empty_payload(&self) -> bool
Check if payload is empty
Sourcepub fn with_dependency(self, dependency: TaskId) -> Self
pub fn with_dependency(self, dependency: TaskId) -> Self
Add a task dependency
Sourcepub fn with_dependencies(
self,
dependencies: impl IntoIterator<Item = TaskId>,
) -> Self
pub fn with_dependencies( self, dependencies: impl IntoIterator<Item = TaskId>, ) -> Self
Add multiple task dependencies
Sourcepub fn has_dependencies(&self) -> bool
pub fn has_dependencies(&self) -> bool
Check if task has any dependencies
Sourcepub fn dependency_count(&self) -> usize
pub fn dependency_count(&self) -> usize
Get the number of dependencies
Sourcepub fn depends_on(&self, task_id: &TaskId) -> bool
pub fn depends_on(&self, task_id: &TaskId) -> bool
Check if a specific task is a dependency
Sourcepub fn is_high_priority(&self) -> bool
pub fn is_high_priority(&self) -> bool
Check if task has high priority (priority > 0)
Sourcepub fn is_low_priority(&self) -> bool
pub fn is_low_priority(&self) -> bool
Check if task has low priority (priority < 0)
Sourcepub fn is_pending(&self) -> bool
pub fn is_pending(&self) -> bool
Check if task is in Pending state
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Check if task is in Running state
Sourcepub fn is_succeeded(&self) -> bool
pub fn is_succeeded(&self) -> bool
Check if task is in Succeeded state
Sourcepub fn is_retrying(&self) -> bool
pub fn is_retrying(&self) -> bool
Check if task is in Retrying state
Sourcepub fn is_reserved(&self) -> bool
pub fn is_reserved(&self) -> bool
Check if task is in Reserved state
Sourcepub fn time_remaining(&self) -> Option<Duration>
pub fn time_remaining(&self) -> Option<Duration>
Get remaining time before timeout
Sourcepub fn time_elapsed(&self) -> Duration
pub fn time_elapsed(&self) -> Duration
Get the time elapsed since task creation
Sourcepub const fn retry_count(&self) -> u32
pub const fn retry_count(&self) -> u32
Get current retry count
Sourcepub const fn retries_remaining(&self) -> u32
pub const fn retries_remaining(&self) -> u32
Get remaining retry attempts
Sourcepub fn is_part_of_workflow(&self) -> bool
pub fn is_part_of_workflow(&self) -> bool
Check if task is part of any workflow
Sourcepub fn get_group_id(&self) -> Option<&Uuid>
pub fn get_group_id(&self) -> Option<&Uuid>
Get group ID if task is part of a group
Sourcepub fn get_chord_id(&self) -> Option<&Uuid>
pub fn get_chord_id(&self) -> Option<&Uuid>
Get chord ID if task is part of a chord
Trait Implementations§
Source§impl Clone for SerializedTask
impl Clone for SerializedTask
Source§fn clone(&self) -> SerializedTask
fn clone(&self) -> SerializedTask
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more