SerializedTask

Struct SerializedTask 

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

  1. Bytes from bytes crate: Provides cheap cloning via reference counting

    use bytes::Bytes;
    pub payload: Bytes,
  2. Arc<[u8]>: Reference-counted slice for shared ownership

    use std::sync::Arc;
    pub payload: Arc<[u8]>,
  3. 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 copying
  • Bytes: Cheap cloning, but requires external dependency
  • Arc<[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: TaskMetadata

Task metadata

§payload: Vec<u8>

Serialized task payload

Implementations§

Source§

impl SerializedTask

Source

pub fn new(name: String, payload: Vec<u8>) -> Self

Source

pub fn with_priority(self, priority: i32) -> Self

Source

pub fn with_max_retries(self, max_retries: u32) -> Self

Source

pub fn with_timeout(self, timeout_secs: u64) -> Self

Source

pub fn with_group_id(self, group_id: Uuid) -> Self

Set the group ID for workflow grouping

Source

pub fn with_chord_id(self, chord_id: Uuid) -> Self

Set the chord ID for barrier synchronization

Source

pub fn age(&self) -> Duration

Get the age of the task (time since creation)

Source

pub fn is_expired(&self) -> bool

Check if the task has expired based on its timeout

Source

pub fn is_terminal(&self) -> bool

Check if the task is in a terminal state (Success or Failure)

Source

pub fn is_active(&self) -> bool

Check if the task is in a running or active state

Source

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.

Source

pub fn validate_with_limit( &self, max_payload_bytes: usize, ) -> Result<(), String>

Validate with custom payload size limit

§Errors

Returns an error if validation fails.

Source

pub fn has_timeout(&self) -> bool

Check if task has a timeout configured

Source

pub fn has_group_id(&self) -> bool

Check if task is part of a group

Source

pub fn has_chord_id(&self) -> bool

Check if task is part of a chord

Source

pub fn has_priority(&self) -> bool

Check if task has custom priority (non-zero)

Source

pub const fn payload_size(&self) -> usize

Get payload size in bytes

Source

pub fn has_empty_payload(&self) -> bool

Check if payload is empty

Source

pub fn with_dependency(self, dependency: TaskId) -> Self

Add a task dependency

Source

pub fn with_dependencies( self, dependencies: impl IntoIterator<Item = TaskId>, ) -> Self

Add multiple task dependencies

Source

pub fn has_dependencies(&self) -> bool

Check if task has any dependencies

Source

pub fn dependency_count(&self) -> usize

Get the number of dependencies

Source

pub fn depends_on(&self, task_id: &TaskId) -> bool

Check if a specific task is a dependency

Source

pub fn is_high_priority(&self) -> bool

Check if task has high priority (priority > 0)

Source

pub fn is_low_priority(&self) -> bool

Check if task has low priority (priority < 0)

Source

pub fn is_pending(&self) -> bool

Check if task is in Pending state

Source

pub fn is_running(&self) -> bool

Check if task is in Running state

Source

pub fn is_succeeded(&self) -> bool

Check if task is in Succeeded state

Source

pub fn is_failed(&self) -> bool

Check if task is in Failed state

Source

pub fn is_retrying(&self) -> bool

Check if task is in Retrying state

Source

pub fn is_reserved(&self) -> bool

Check if task is in Reserved state

Source

pub fn time_remaining(&self) -> Option<Duration>

Get remaining time before timeout

Source

pub fn time_elapsed(&self) -> Duration

Get the time elapsed since task creation

Source

pub fn can_retry(&self) -> bool

Check if task can be retried

Source

pub const fn retry_count(&self) -> u32

Get current retry count

Source

pub const fn retries_remaining(&self) -> u32

Get remaining retry attempts

Source

pub fn is_part_of_workflow(&self) -> bool

Check if task is part of any workflow

Source

pub fn get_group_id(&self) -> Option<&Uuid>

Get group ID if task is part of a group

Source

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

Source§

fn clone(&self) -> SerializedTask

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 SerializedTask

Source§

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

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

impl<'de> Deserialize<'de> for SerializedTask

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 Display for SerializedTask

Source§

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

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

impl Serialize for SerializedTask

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

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