Struct TaskManager

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

Task manager that schedules and runs tasks on schedule, indefinitely

Implementations§

Source§

impl TaskManager

Source

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

Source

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 logging
  • interval - The period / frequency at which this task will run
  • task - 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

Source

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 logging
  • interval - The period / frequency at which this task will run
  • offset - The offset at which this interval will begin
  • task - 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…)
Source

pub async fn run(&self)

Run the tasks in the task manager on schedule until the process dies

Source

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

Source§

fn clone(&self) -> TaskManager

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for TaskManager

Source§

fn default() -> Self

Defaults to 500 ms for checking for tasks to run

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more