Skip to main content

TaskMessage

Struct TaskMessage 

Source
pub struct TaskMessage {
Show 18 fields pub id: TaskId, pub task_name: String, pub queue: String, pub payload: Value, pub state: TaskState, pub retries: u32, pub max_retries: u32, pub created_at: DateTime<Utc>, pub updated_at: DateTime<Utc>, pub eta: Option<DateTime<Utc>>, pub headers: HashMap<String, String>, pub parent_id: Option<TaskId>, pub correlation_id: Option<String>, pub group_id: Option<String>, pub group_total: Option<u32>, pub chord_callback: Option<Box<TaskMessage>>, pub priority: Option<u8>, pub dedup_key: Option<String>,
}
Expand description

A task message that flows through the broker.

Fields§

§id: TaskId

Unique task identifier.

§task_name: String

Registered task name (e.g., “send_email”).

§queue: String

Target queue name.

§payload: Value

Serialized task payload.

§state: TaskState

Current task state.

§retries: u32

Current retry count.

§max_retries: u32

Maximum allowed retries.

§created_at: DateTime<Utc>

When the message was created.

§updated_at: DateTime<Utc>

When the message was last updated.

§eta: Option<DateTime<Utc>>

Optional ETA — earliest time the task should execute.

§headers: HashMap<String, String>

Arbitrary headers for middleware / tracing propagation.

§parent_id: Option<TaskId>

Parent task ID for workflow tracking.

§correlation_id: Option<String>

Correlation ID for tracing an entire workflow.

§group_id: Option<String>

Group ID this task belongs to.

§group_total: Option<u32>

Total number of tasks in the group.

§chord_callback: Option<Box<TaskMessage>>

Chord callback to enqueue when all group members complete.

§priority: Option<u8>

Task priority (0–9, higher = more urgent). Broker-specific support.

§dedup_key: Option<String>

Deduplication key. If set, brokers may skip enqueue when a duplicate exists.

Implementations§

Source§

impl TaskMessage

Source

pub fn new( task_name: impl Into<String>, queue: impl Into<String>, payload: Value, ) -> Self

Create a new task message with defaults.

Source

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

Set max retries.

Source

pub fn with_eta(self, eta: DateTime<Utc>) -> Self

Set ETA.

Source

pub fn with_header( self, key: impl Into<String>, value: impl Into<String>, ) -> Self

Add a header.

Source

pub fn with_parent_id(self, parent_id: TaskId) -> Self

Set parent task ID for workflow tracking.

Source

pub fn with_correlation_id(self, correlation_id: impl Into<String>) -> Self

Set correlation ID for tracing an entire workflow.

Source

pub fn with_group(self, group_id: impl Into<String>, group_total: u32) -> Self

Set group metadata.

Source

pub fn with_chord_callback(self, callback: TaskMessage) -> Self

Set chord callback.

Source

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

Set task priority (clamped to 0–9, higher = more urgent).

Source

pub fn with_dedup_key(self, key: impl Into<String>) -> Self

Set an explicit deduplication key.

Source

pub fn with_content_dedup(self) -> Self

Auto-generate a dedup key by hashing task_name + payload.

Uses FNV-1a (64-bit) which is deterministic across Rust versions and platforms, unlike DefaultHasher which may change between releases.

Trait Implementations§

Source§

impl Clone for TaskMessage

Source§

fn clone(&self) -> TaskMessage

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 TaskMessage

Source§

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

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

impl<'de> Deserialize<'de> for TaskMessage

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 TaskMessage

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, 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<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>,