Skip to main content

JobCtx

Struct JobCtx 

Source
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 Storage

The 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 RateLimiter

Cluster-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: JobId

Id of the row being processed.

§process_id: &'a str

Worker name ("{queue}-{slot}-{host_id}").

§host_id: &'a str

Process-boot ULID so handlers can correlate logs with the originating process across restarts.

§cancel: CancellationToken

Honor 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<'_>

Source

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.

Source

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§

Source§

impl Debug for JobCtx<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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