Struct JobRunner

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

The main coordinator for running jobs. It exposes methods to start and stop jobs, as well as to get the status of a job or all jobs.

Each job added to the JobRunner is given a dedicated thread to execute on, therefore the number of threads created by the JobRunner is equal to the number of jobs which are started.

Implementations§

Source§

impl JobRunner

Source

pub fn new() -> Self

Initialize a new JobRunner with no jobs started yet.

Source

pub fn join_on_drop(&mut self, join_on_drop: bool) -> &mut Self

Allows you to configure the JobRunner to wait for job threads to exit when dropped. The default value for this option is false, which is equivalent to calling the stop_all method at drop time. Passing true for this option is equivalent to calling the join_all method at drop time.

Source

pub fn status(&self, job_name: &str) -> Option<JobStatus>

Gets the latest status of a specific job by the job’s name.

Source

pub fn statuses(&self) -> impl Iterator<Item = (&String, JobStatus)>

Gets an iterator over all job statuses. The iterator item tuple’s first entry is the name of the job.

Source

pub fn request_execution(&self, job_name: &str)

Request that a specific job execute immediately. How soon the job executes depends on whether it is currently executing, or whether it is sleeping waiting for its next regular execution. If the job is currently executing, then once the current execution ends, the job will immediately begin executing again rather than sleeping. If the job is currently sleeping, then the sleep will be interrupted and the job will begin executing on its dedicated thread.

No matter how many times method is called before the job thread is actually able to start the next execution, the job will only execute once for all those requests. This can happen if for example a long-running job is executing and request_execution is called multiple times before the currently-executing run finishes. In that case, the job will immediately begin executing after the current run finishes, but after that follow up run finishes then the job will go back to its normal schedule (assuming no other request_execution calls have arrived in the mean time).

Source

pub fn start(&mut self, job: Job) -> Result<()>

Registers a job and starts it executing on a dedicated thread. The job schedule’s Schedule::next_start_delay method will be called to determine when the first job execution should occur.

Source

pub fn stop_all(&mut self)

Signal to all jobs to stop executing. This will prevent any further job runs from starting, but will not preemptively interrupt any currently-executing job runs. Although the join_all method also signals all jobs to stop executing, this method can still be useful to call at the start of application shut down, if you have other parts of the program that you want to begin shutting down too before calling the blocking join_all method. This method signals, but does not block.

Source

pub fn join_all(&mut self)

Signal to all jobs to stop executing and then waits for the job threads to exit before returning. Jobs that are waiting for the next scheduled run will exit immediately, but currently-executing jobs will be allowed to complete their current run - the JobRunner does not itself define any mechanism for preemptively interrupting running jobs. That means that how long this method takes to execute depends on how long the slowest currently-running job takes to finish its run. If you have particularly long-running jobs, you may want to pass them a separate cancellation token that you call before invoking this method.

Trait Implementations§

Source§

impl Default for JobRunner

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for JobRunner

Source§

fn drop(&mut self)

Executes the destructor for this type. 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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.