pub struct Schedule { /* private fields */ }Expand description
Schedule - main entry point for scheduling tasks
Provides methods for registering and running scheduled tasks. Tasks can be registered via trait implementations or closures.
§Example
ⓘ
use ferro_rs::Schedule;
pub fn register(schedule: &mut Schedule) {
// Register a struct implementing Task trait
schedule.add(
schedule.task(MyCleanupTask::new())
.daily()
.at("03:00")
.name("cleanup")
);
// Or use a closure
schedule.add(
schedule.call(|| async {
println!("Hello!");
Ok(())
}).daily().at("03:00").name("greeting")
);
}Implementations§
Source§impl Schedule
impl Schedule
Sourcepub fn task<T: Task + 'static>(&self, task: T) -> TaskBuilder
pub fn task<T: Task + 'static>(&self, task: T) -> TaskBuilder
Sourcepub fn call<F, Fut>(&mut self, f: F) -> TaskBuilder
pub fn call<F, Fut>(&mut self, f: F) -> TaskBuilder
Sourcepub fn add(&mut self, builder: TaskBuilder) -> &mut Self
pub fn add(&mut self, builder: TaskBuilder) -> &mut Self
Sourcepub async fn run_due_tasks(&self) -> Vec<(&str, Result<(), FrameworkError>)>
pub async fn run_due_tasks(&self) -> Vec<(&str, Result<(), FrameworkError>)>
Run all due tasks once
Returns a vector of results for each task that was run.
Sourcepub async fn run_all_tasks(&self) -> Vec<(&str, Result<(), FrameworkError>)>
pub async fn run_all_tasks(&self) -> Vec<(&str, Result<(), FrameworkError>)>
Run all tasks regardless of their schedule
Useful for testing or manual triggering.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Schedule
impl !RefUnwindSafe for Schedule
impl Send for Schedule
impl Sync for Schedule
impl Unpin for Schedule
impl UnsafeUnpin for Schedule
impl !UnwindSafe for Schedule
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more