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
- Live committed reads; no cached state on handles. Every
load()is a fresh read. - Order preservation:
await_all/load_allresults[i] ↔ handles[i]. - Cancel safety: dropping an in-flight
await_all/await_completionfuture (select!loser) leaks nothing and a re-registered wait resolves — the dominant call pattern istokio::select!againstCurrentJob::shutdown_requested. - 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 — soload()never reportsPending/Runningfor a finished job, regardless of isolation level. - Honest absence:
JobSnapshot::execution_state⇒Ok(None)on no-row/no-state;load()⇒Err(Find)only if the job never existed. - Keyed/resident handle identity: both
KeyedJobSpawner::spawnandResidentJobSpawner::spawngenerate 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 — seecrate::ResidentJobCompletion). Either way, callers read the id back from the handle.
Implementations§
Source§impl JobHandle
impl JobHandle
Sourcepub async fn load(&self) -> Result<JobSnapshot, JobError>
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.
Sourcepub async fn execution_state<S: DeserializeOwned>(
&self,
) -> Result<Option<S>, JobError>
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.
Sourcepub async fn await_completion(
&self,
timeout: Duration,
) -> Result<JobOutcome, JobError>
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 Extend<JobHandle> for JobHandles
impl Extend<JobHandle> for JobHandles
Source§fn extend<I: IntoIterator<Item = JobHandle>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = JobHandle>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: T)
fn extend_one(&mut self, item: T)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl FromIterator<JobHandle> for JobHandles
impl FromIterator<JobHandle> for JobHandles
Auto Trait Implementations§
impl !RefUnwindSafe for JobHandle
impl !UnwindSafe for JobHandle
impl Freeze for JobHandle
impl Send for JobHandle
impl Sync for JobHandle
impl Unpin for JobHandle
impl UnsafeUnpin for JobHandle
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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