pub struct TaskManager { /* private fields */ }Expand description
Task manager that schedules and runs tasks on schedule, until cancelled
Implementations§
Source§impl TaskManager
impl TaskManager
pub fn new() -> Self
Sourcepub fn add<T>(&mut self, name: &str, interval: Duration, task: T)where
T: AsyncTask + 'static,
pub fn add<T>(&mut self, name: &str, interval: Duration, task: T)where
T: AsyncTask + 'static,
Add a task to be run periodically on an interval, without an offset
name- Unique, descriptive name for debug + error logginginterval- The period / frequency at which this task will runtask- The actual task / job / work that will be run on the interval
To explain interval, consider 3 examples:
- Interval 30 seconds == task will run every half minute (00:00:30, 00:01:00, 00:01:30…)
- Interval 3,600 seconds (60 minutes) == task will run at the top of the hour (02:00:00, 03:00:00, 04:00:00…)
- Interval 86,400 seconds (1 day / 24 hours) == task will run at midnight every day (00:00:00)
This system runs on time passing only (with default features) and should be unaffected by any daylight savings times, although the starting runs of all tasks do initialize based on current system clock, whatever timezone that is
Sourcepub fn add_offset<T>(
&mut self,
name: &str,
interval: Duration,
offset: Duration,
task: T,
)where
T: AsyncTask + 'static,
pub fn add_offset<T>(
&mut self,
name: &str,
interval: Duration,
offset: Duration,
task: T,
)where
T: AsyncTask + 'static,
Add a task to be run periodically on an interval, with an offset
name- Unique, descriptive name for debug + error logginginterval- The period / frequency at which this task will runoffset- The offset at which this interval will begintask- The actual task / job / work that will be run on the interval
To explain offset, consider 3 examples, all with an interval of 60 minutes (1 hour):
- Offset not provided (0) == task will run at the top of the hour (2:00, 3:00, 4:00…)
- Offset 30 min == task will run at half past the hour every hour (2:30, 3:30, 4:30…)
- Offset 15 min == task will run at quarter past the hour every hour (2:15, 3:15, 4:15…)
Sourcepub async fn run_forever(self)
pub async fn run_forever(self)
Run the tasks in the task manager on schedule until the process dies
Sourcepub async fn run_with_cancel(self, cancel: CancellationToken)
pub async fn run_with_cancel(self, cancel: CancellationToken)
Run the tasks in the task manager on schedule until cancelled
This runs the set of tasks at this moment – tasks will not change without cancelling and re-running
cancel- token to cancel() to stop the manager/loop
Sourcepub async fn run_with_signal(self, wait: Duration)
pub async fn run_with_signal(self, wait: Duration)
Run the tasks in the task manager on schedule until the process is interrupted
wait- time to wait before forcing abort of tasks loop after signal (cancel)
Trait Implementations§
Source§impl Clone for TaskManager
impl Clone for TaskManager
Source§fn clone(&self) -> TaskManager
fn clone(&self) -> TaskManager
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more