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
impl JobRunner
Sourcepub fn join_on_drop(&mut self, join_on_drop: bool) -> &mut Self
pub fn join_on_drop(&mut self, join_on_drop: bool) -> &mut Self
Sourcepub fn status(&self, job_name: &str) -> Option<JobStatus>
pub fn status(&self, job_name: &str) -> Option<JobStatus>
Gets the latest status of a specific job by the job’s name.
Sourcepub fn statuses(&self) -> impl Iterator<Item = (&String, JobStatus)>
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.
Sourcepub fn request_execution(&self, job_name: &str)
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).
Sourcepub fn start(&mut self, job: Job) -> Result<()>
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.
Sourcepub fn stop_all(&mut self)
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.
Sourcepub fn join_all(&mut self)
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.