pub struct Envelope {
pub job_id: Uuid,
pub job_type: String,
pub queue: String,
pub attempt: u32,
pub enqueued_at_ms: u64,
pub deferrals: u32,
pub priority: u8,
pub payload: Value,
}Expand description
Wire format for a job message. Serialized as JSON in the message body.
Fields§
§job_id: UuidUnique id, stable across retries.
job_type: StringJob::NAME of the payload.
queue: StringBroker queue name this envelope was published to.
attempt: u321-based attempt counter. First delivery is attempt 1.
enqueued_at_ms: u64Unix epoch milliseconds when the job was first enqueued.
deferrals: u32How often this job was deferred (see crate::JobError::Deferred).
Independent of Envelope::attempt: a deferral is not a failed attempt.
Defaults to 0 so envelopes written before this field existed still decode.
priority: u8Broker message priority; 0 (the default) is normal work.
Deferred envelopes carry the highest level their queue supports
(crate::QueueConfig::max_priority) so they run ahead of the backlog. A queue
that is not a priority queue makes the broker ignore this. Only the scheduling
action that just happened decides this: a deferral raises it,
Envelope::next_attempt puts it back to 0. Defaults to 0 so envelopes
written before this field existed still decode.
payload: ValueThe serialized job.
Implementations§
Source§impl Envelope
impl Envelope
Sourcepub fn decode<J: Job>(&self) -> Result<J>
pub fn decode<J: Job>(&self) -> Result<J>
Deserialize the payload as J. Does not check job_type.
Sourcepub fn next_attempt(&self) -> Self
pub fn next_attempt(&self) -> Self
Copy of this envelope with attempt incremented and priority back at 0.
deferrals rides along untouched, so a retry still knows how often the job was
deferred. priority does not: a retry is scheduled like any other failed
attempt and must not jump the backlog just because the job happened to defer
itself earlier. Only the scheduling action that just happened decides the
priority. See Envelope::deferred for the one that raises it.
Sourcepub fn deferred(&self, priority: u8) -> Self
pub fn deferred(&self, priority: u8) -> Self
Copy of this envelope for a deferral: deferrals + 1 and priority set.
attempt, job_id, job_type, queue and enqueued_at_ms are unchanged:
a deferral is not a failed attempt, and age keeps measuring the time since
the job was first enqueued. priority is normally
QueueConfig::max_priority.unwrap_or(0) of the job’s queue, so the job comes
back ahead of everything published normally. It lasts only until the job is
next scheduled some other way: Envelope::next_attempt drops it back to 0.
See crate::JobError::Deferred.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_bytes(bytes: &[u8]) -> Result<Self>
Parse an envelope from a JSON message body.