Skip to main content

JobHandle

Struct JobHandle 

Source
pub struct JobHandle { /* private fields */ }
Expand description

A minted, cloneable per-job capability: the public way to observe and await a job you did not run yourself.

Obtain one from Jobs::handle, Jobs::handles, ResidentJobSpawner::spawn, or KeyedJobSpawner::spawn.

The handle is a capability, not a value: it holds no cached state and exposes exactly two operations — load for a point-in-time JobSnapshot, and await_completion for the terminal outcome.

§Contracts

  1. Live committed reads; no cached state on handles. Every load() is a fresh read.
  2. Order preservation: await_all/load_all results[i] ↔ handles[i].
  3. Cancel safety: dropping an in-flight await_all/await_completion future (select! loser) leaks nothing and a re-registered wait resolves — the dominant call pattern is tokio::select! against CurrentJob::shutdown_requested.
  4. Torn-read-free load(): the entity is authoritative for terminal state — a terminal entity discards any execution row a concurrent completion left visible mid-commit — so load() never reports Pending/Running for a finished job, regardless of isolation level.
  5. Honest absence: JobSnapshot::execution_stateOk(None) on no-row/no-state; load()Err(Find) only if the job never existed.
  6. Keyed/resident handle identity: both KeyedJobSpawner::spawn and ResidentJobSpawner::spawn generate the job’s id internally; on the duplicate path the returned handle’s id is the PERSISTED job’s id, not a new one — for keyed, the still-LIVE job holding the key; for resident, the job that exists at all (possibly long-terminal, though a resident job never actually reaches terminal — see crate::ResidentJobCompletion). Either way, callers read the id back from the handle.

Implementations§

Source§

impl JobHandle

Source

pub fn id(&self) -> JobId

The id of the job this handle observes.

Source

pub async fn load(&self) -> Result<JobSnapshot, JobError>

Load a point-in-time JobSnapshot: runtime status plus the committed execution state, config, and return value.

§Errors

Returns JobError::Find if the job never existed.

Source

pub async fn execution_state<S: DeserializeOwned>( &self, ) -> Result<Option<S>, JobError>

Read back only the committed execution state, decoded as S.

A cheap point-read: one single-row SELECT on job_executions, no entity hydration and no snapshot reconciliation — for hot poll loops (e.g. a caught-up barrier) that only need the execution state and would otherwise pay a full load whose cost grows with the event log. Use load() when you need a consistent status/config view.

Honest absence: Ok(None) on a missing row (never spawned, or already terminal) or unset state. Does not distinguish “never existed” from “terminal” — use load if that matters.

§Errors

Returns JobError::CouldNotDeserializeExecutionState if the stored state does not decode into S.

Source

pub async fn await_completion( &self, timeout: Duration, ) -> Result<JobOutcome, JobError>

Block until the job reaches a terminal state (completed or errored) and return the outcome together with any result value the runner attached via CurrentJob::set_result.

The timeout is REQUIRED: the await is structurally bounded. Wait-forever is expressed only by an explicit caller loop that re-awaits on JobError::TimedOut — each re-await re-registers a fresh waiter, which is also what makes a lost in-memory notification self-heal instead of wedging.

§Errors

Returns JobError::RouterNotStarted if called before Jobs::start_poll. Returns JobError::Find if the job does not exist. Returns JobError::TimedOut if the timeout elapses first. Returns JobError::AwaitCompletionShutdown if the notification channel is dropped (e.g., during shutdown) before delivering the terminal state.

Trait Implementations§

Source§

impl Clone for JobHandle

Source§

fn clone(&self) -> JobHandle

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Extend<JobHandle> for JobHandles

Source§

fn extend<I: IntoIterator<Item = JobHandle>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: T)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl FromIterator<JobHandle> for JobHandles

Source§

fn from_iter<I: IntoIterator<Item = JobHandle>>(iter: I) -> Self

Creates a value from an iterator. Read more

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<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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