pub struct Scheduler {
pub broker: Box<dyn Broker>,
/* private fields */
}
Expand description
A Scheduler
is in charge of executing scheduled tasks when they are due.
It is somehow similar to a future, in the sense that by itself it does nothing,
and execution is driven by an “executor” (the Beat
) which
is in charge of calling the scheduler tick
.
Internally it uses a min-heap to store tasks and efficiently retrieve the ones that are due for execution.
Fields§
§broker: Box<dyn Broker>
Implementations§
source§impl Scheduler
impl Scheduler
sourcepub fn new(broker: Box<dyn Broker>) -> Scheduler
pub fn new(broker: Box<dyn Broker>) -> Scheduler
Create a new scheduler which uses the given broker
.
sourcepub fn schedule_task<S>(
&mut self,
name: String,
message_factory: Box<dyn TryCreateMessage>,
queue: String,
schedule: S
)where
S: Schedule + 'static,
pub fn schedule_task<S>( &mut self, name: String, message_factory: Box<dyn TryCreateMessage>, queue: String, schedule: S )where S: Schedule + 'static,
Schedule the execution of a task.
sourcepub fn get_scheduled_tasks(&mut self) -> &mut BinaryHeap<ScheduledTask>
pub fn get_scheduled_tasks(&mut self) -> &mut BinaryHeap<ScheduledTask>
Get all scheduled tasks.
sourcepub async fn tick(&mut self) -> Result<SystemTime, BeatError>
pub async fn tick(&mut self) -> Result<SystemTime, BeatError>
Tick once. This method checks if there is a scheduled task which is due
for execution and, if so, sends it to the broker.
It returns the time by which tick
should be called again.
Auto Trait Implementations§
impl !RefUnwindSafe for Scheduler
impl !Send for Scheduler
impl !Sync for Scheduler
impl Unpin for Scheduler
impl !UnwindSafe for Scheduler
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more