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: StringThe ID of the currently executing job.
trace_id: Option<String>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: u32Use 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
impl JobContext
Sourcepub fn new_direct(job_id: &str) -> JobContext
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.
Sourcepub fn emit_progress(&self, current: u32, total: u32)
pub fn emit_progress(&self, current: u32, total: u32)
Sourcepub fn is_cancelled(&self) -> bool
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).