pub struct QueueJob<T>{
pub id: String,
pub trace_id: Option<String>,
pub trace_ctx: Option<TraceCtx>,
pub attempt_id: Option<AttemptId>,
pub trial_id: Option<TrialId>,
pub priority: QueuePriority,
pub status: QueueJobStatus,
pub data: T,
pub created_at: Option<String>,
pub started_at: Option<String>,
pub completed_at: Option<String>,
pub error_message: Option<String>,
}Expand description
A generic queue job carrying a custom data payload.
The data field is stored as JSON in SQLite and deserialized back when the
executor picks up the job. Your data type must implement Serialize,
DeserializeOwned, Clone, Send, and Sync.
When creating jobs via QueueJob::new, only id, priority, and data
are meaningful — the remaining fields (status, created_at, started_at,
completed_at, error_message) are set to defaults and populated by the
database when reading job records back.
§Trace and retry primitives
The canonical trace/retry fields are:
trace_ctx: canonicalstack_ids::TraceCtxfor end-to-end correlationattempt_id: one per re-enqueue (this crate is the retry owner)trial_id: one per concrete execution attempt
The legacy trace_id: Option<String> field is preserved for backward
compatibility and is kept in sync with trace_ctx automatically.
Fields§
§id: String§trace_id: Option<String>Phase status: compatibility / migration-only.
Legacy trace identifier for end-to-end correlation.
The canonical replacement is trace_ctx.
Use stack_ids::TraceCtx::from_legacy_trace_id() to convert.
Removal condition: replaced when all callers migrate.
trace_ctx: Option<TraceCtx>Canonical trace context for end-to-end correlation.
Replaces the legacy trace_id field. The trace ID string is
extractable via trace_ctx.trace_id for DB storage (the DB schema
stores trace_id TEXT and is NOT changed).
attempt_id: Option<AttemptId>Canonical attempt identity — one per re-enqueue.
This crate is the retry owner: each re-enqueue creates a new
AttemptId. Retries within the same attempt use different TrialIds.
trial_id: Option<TrialId>Canonical trial identity — one per concrete execution.
Each time the executor picks up a job for execution, a new TrialId
is generated. Multiple trials may share the same AttemptId.
priority: QueuePriority§status: QueueJobStatus§data: T§created_at: Option<String>Only populated when reading from DB.
started_at: Option<String>Only populated when reading from DB.
completed_at: Option<String>Only populated when reading from DB.
error_message: Option<String>Only populated when reading from DB.
Implementations§
Source§impl<T> QueueJob<T>
impl<T> QueueJob<T>
Sourcepub fn new(data: T) -> QueueJob<T>
pub fn new(data: T) -> QueueJob<T>
Create a new job with a generated UUID and Normal priority.
A fresh AttemptId is generated automatically (this crate is the
retry owner — each enqueue is a new attempt).
Sourcepub fn with_priority(self, priority: QueuePriority) -> QueueJob<T>
pub fn with_priority(self, priority: QueuePriority) -> QueueJob<T>
Set the priority for this job (builder pattern).
Sourcepub fn with_id(self, id: String) -> QueueJob<T>
pub fn with_id(self, id: String) -> QueueJob<T>
Set a custom ID for this job (builder pattern).
Sourcepub fn with_trace_id(self, trace_id: impl Into<String>) -> QueueJob<T>
pub fn with_trace_id(self, trace_id: impl Into<String>) -> QueueJob<T>
Phase status: compatibility / migration-only.
Attach an optional trace ID string for end-to-end correlation.
Prefer with_trace_ctx() for new code.
Removal condition: replaced when all callers migrate.
Sourcepub fn with_trace_ctx(self, ctx: TraceCtx) -> QueueJob<T>
pub fn with_trace_ctx(self, ctx: TraceCtx) -> QueueJob<T>
Attach a canonical stack_ids::TraceCtx for end-to-end correlation.
Also sets the legacy trace_id string for DB storage compatibility
(the DB schema stores trace_id TEXT and is NOT changed).
Sourcepub fn with_attempt_id(self, attempt_id: AttemptId) -> QueueJob<T>
pub fn with_attempt_id(self, attempt_id: AttemptId) -> QueueJob<T>
Set a pre-existing AttemptId (e.g., when reconstructing from DB).
Normally callers do not need this — new() generates a fresh
AttemptId automatically.
Sourcepub fn with_trial_id(self, trial_id: TrialId) -> QueueJob<T>
pub fn with_trial_id(self, trial_id: TrialId) -> QueueJob<T>
Set a TrialId (normally assigned by the executor, not callers).
Sourcepub fn resolve_trace_ctx(&self) -> Option<TraceCtx>
pub fn resolve_trace_ctx(&self) -> Option<TraceCtx>
Get the canonical TraceCtx, preferring the canonical field,
falling back to reconstruction from the legacy trace_id string.
Returns None if neither field is set.
Sourcepub fn trace_ctx_compat(&self) -> Option<TraceCtx>
pub fn trace_ctx_compat(&self) -> Option<TraceCtx>
Phase status: compatibility / migration-only.
Convert the stored trace ID to a canonical stack_ids::TraceCtx.
Returns None if no trace ID is set.
Prefer resolve_trace_ctx() for new code.