pub struct JobCtx<'a> {
pub storage: &'a Storage,
pub router: &'a (dyn Router + Send + Sync),
pub rate_limit: &'a RateLimiter,
pub job_id: JobId,
pub process_id: &'a str,
pub host_id: &'a str,
pub cancel: CancellationToken,
}Expand description
Per-invocation context passed to a handler’s run.
Handlers should use ctx.enqueue(req) to chain follow-up work —
it applies the runtime’s router so req.queue_name = None is
resolved automatically.
Fields§
§storage: &'a StorageThe backend-agnostic storage bundle. Handlers usually only
need storage.jobs for follow-up enqueues; the other Arcs
are exposed for read-only inspection.
router: &'a (dyn Router + Send + Sync)The router used to fill in queue_name on enqueues.
rate_limit: &'a RateLimiterCluster-wide rate-limit budget. Handlers that talk to an
external API (acquire("slack"), acquire("gh")) gate
every upstream call through this so a sibling pod doesn’t
independently spend the same budget.
job_id: JobIdId of the row being processed.
process_id: &'a strWorker name ("{queue}-{slot}-{host_id}").
host_id: &'a strProcess-boot ULID so handlers can correlate logs with the originating process across restarts.
cancel: CancellationTokenHonor this if the handler can cooperatively shut down — the supervisor signals it when the queue is paused or the process is exiting.
Implementations§
Source§impl JobCtx<'_>
impl JobCtx<'_>
Sourcepub async fn enqueue(&self, req: EnqueueRequest) -> Result<EnqueueOutcome>
pub async fn enqueue(&self, req: EnqueueRequest) -> Result<EnqueueOutcome>
Enqueue a follow-up job from inside a handler. The router
fills in queue_name when the request doesn’t pin one.
Retries up to 3× on transient writer-lock conflicts so a
handler doesn’t abort a long fan-out loop because of a
momentary lock race against another worker.
Sourcepub async fn enqueue_bulk(
&self,
reqs: Vec<EnqueueRequest>,
) -> Result<Vec<EnqueueOutcome>>
pub async fn enqueue_bulk( &self, reqs: Vec<EnqueueRequest>, ) -> Result<Vec<EnqueueOutcome>>
Enqueue many follow-up jobs in a single transaction. Use this
from bootstrap-style handlers that produce hundreds-to-thousands
of sub-jobs in one go — otherwise we’d take and release the
underlying writer lock N times and starve heartbeats. Same
3× transient-conflict retry as Self::enqueue.
Trait Implementations§
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for JobCtx<'a>
impl<'a> !UnwindSafe for JobCtx<'a>
impl<'a> Freeze for JobCtx<'a>
impl<'a> Send for JobCtx<'a>
impl<'a> Sync for JobCtx<'a>
impl<'a> Unpin for JobCtx<'a>
impl<'a> UnsafeUnpin for JobCtx<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more