pub struct JobRegistry {
next_id: AtomicU64,
jobs: Mutex<BTreeMap<u64, JobRecord>>,
updates: Sender<JobStatus>,
}Expand description
State of the jobs of a session.
Fields§
§next_id: AtomicU64ID of the next job.
jobs: Mutex<BTreeMap<u64, JobRecord>>State of each job, by ID.
updates: Sender<JobStatus>Channel every job change is sent to.
Implementations§
Source§impl JobRegistry
impl JobRegistry
Sourcepub fn has_unfinished_jobs(&self) -> bool
pub fn has_unfinished_jobs(&self) -> bool
Returns if any job is queued or running.
Sourcepub fn start(&self, job: u64) -> bool
pub fn start(&self, job: u64) -> bool
Marks a queued job as running.
§Returns
false if the job was cancelled or is unknown, so it must not run.
Sourcepub fn set_progress(&self, job: u64, progress: u8)
pub fn set_progress(&self, job: u64, progress: u8)
Sets how far along a running job is, from 0 to 100.
Only increases are kept, as parallel steps of a job may report their progress out of order.
Sourcepub fn finish_cancelled(&self, job: u64)
pub fn finish_cancelled(&self, job: u64)
Ends a job as cancelled, even if it already started.
Sourcepub fn finish(&self, job: u64, outcome: RpcOutcome)
pub fn finish(&self, job: u64, outcome: RpcOutcome)
Ends a job with the outcome of its method.
Sourcepub fn cancel(&self, job: u64) -> Result<JobStatus, ApiError>
pub fn cancel(&self, job: u64) -> Result<JobStatus, ApiError>
Cancels a job that hasn’t started yet.
§Errors
Fails if the job is unknown, or if it already started.
Sourcepub fn status(&self, job: u64) -> Option<JobStatus>
pub fn status(&self, job: u64) -> Option<JobStatus>
Returns the state of a job, or None if it’s unknown.
Sourcepub fn record(&self, job: u64) -> Option<JobRecord>
pub fn record(&self, job: u64) -> Option<JobRecord>
Returns the state of a job with when it was created and last changed, or None if it’s unknown.
Sourcepub fn subscribe(&self) -> Receiver<JobStatus>
pub fn subscribe(&self) -> Receiver<JobStatus>
Returns a receiver of every job change from now on.
Sourcepub async fn wait(&self, job: u64, timeout: Duration) -> Option<JobStatus>
pub async fn wait(&self, job: u64, timeout: Duration) -> Option<JobStatus>
Waits for a job to end, up to timeout.
§Returns
The state of the job when it ended, or when the wait timed out. None if the job is unknown.
Sourcefn transition(
&self,
job: u64,
change: impl FnOnce(&JobState) -> Option<JobState>,
) -> Option<JobStatus>
fn transition( &self, job: u64, change: impl FnOnce(&JobState) -> Option<JobState>, ) -> Option<JobStatus>
Changes the state of a job with change, which returns the new state, or None to keep the current one.
§Returns
The new state of the job, or None if it’s unknown or didn’t change.
Sourcefn set(&self, status: JobStatus)
fn set(&self, status: JobStatus)
Stores the state of a job, forgetting the oldest ended jobs over MAX_ENDED_JOBS, and notifies it.
Trait Implementations§
Source§impl Debug for JobRegistry
impl Debug for JobRegistry
Auto Trait Implementations§
impl !Freeze for JobRegistry
impl !RefUnwindSafe for JobRegistry
impl !UnwindSafe for JobRegistry
impl Send for JobRegistry
impl Sync for JobRegistry
impl Unpin for JobRegistry
impl UnsafeUnpin for JobRegistry
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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 moreimpl<T> MaybeSend for T
impl<T> MaybeSync for T
§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.