pub struct TaskManager { /* private fields */ }
Expand description
Task manager that schedules and runs tasks on schedule, indefinitely
Implementations§
Source§impl TaskManager
impl TaskManager
Sourcepub fn new(millis: u64) -> Self
pub fn new(millis: u64) -> Self
Specify the ms for frequency/interval of checking for tasks to run
Also consider ::default()
for a sensible default for tasks on intervals of seconds and above
Sourcepub async fn add<T>(&self, name: &str, interval: Duration, task: T)where
T: AsyncTask + 'static,
pub async fn add<T>(&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 async fn add_offset<T>(
&self,
name: &str,
interval: Duration,
offset: Duration,
task: T,
)where
T: AsyncTask + 'static,
pub async fn add_offset<T>(
&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_with_signal(&self)
pub async fn run_with_signal(&self)
Run the tasks in the task manager on schedule until the process is interrupted with ctl-c
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