Skip to main content

JobContext

Struct JobContext 

Source
pub struct JobContext {
    pub job_id: String,
    pub trace_id: Option<String>,
    pub trace_ctx: Option<TraceCtx>,
    pub attempt_id: Option<AttemptId>,
    pub trial_id: Option<TrialId>,
    pub worker_id: Option<String>,
    pub attempt_count: u32,
    /* private fields */
}
Expand description

Context provided to job handlers during execution.

Gives access to an event emitter for reporting progress and methods for checking cancellation.

Fields§

§job_id: String

The ID of the currently executing job.

§trace_id: Option<String>
👎Deprecated:

Use trace_ctx instead. Will be removed when all consumers migrate.

Phase status: compatibility / migration-only.

Legacy trace ID for correlating queue work with upstream orchestration. Prefer trace_ctx for new code.

§trace_ctx: Option<TraceCtx>

Canonical trace context for end-to-end correlation.

§attempt_id: Option<AttemptId>

Canonical attempt identity — one per re-enqueue.

§trial_id: Option<TrialId>

Canonical trial identity — one per concrete execution.

§worker_id: Option<String>

Worker identity currently holding the job lease.

§attempt_count: u32
👎Deprecated:

Use attempt_id/trial_id instead. Will be removed when all consumers migrate.

Phase status: compatibility / migration-only.

Current attempt count (legacy counter).

Implementations§

Source§

impl JobContext

Source

pub fn new_direct(job_id: &str) -> JobContext

Create a context for direct (non-queued) job execution.

This creates a lightweight context backed by an in-memory SQLite database and a no-op event emitter. Useful for CLI tools that execute jobs directly without going through the queue infrastructure.

Source

pub fn emit_progress(&self, current: u32, total: u32)

Emit a progress event.

§Arguments
  • current - Current step number
  • total - Total number of steps
Source

pub fn is_cancelled(&self) -> bool

Check if this job has been cancelled.

Call this periodically during long-running jobs to support cooperative cancellation. If it returns true, your handler should return Err(QueueError::Cancelled).

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