pub struct CronScheduler { /* private fields */ }Expand description
调度器根级 re-export(供 core 内部 dogfood 使用)
Implementations§
Source§impl CronScheduler
impl CronScheduler
pub fn new() -> CronScheduler
pub fn parse_cron(&self, expr: &str) -> Result<CronExpr, SchedulerError>
pub fn next_run_time( &self, expr: &str, from: DateTime<Utc>, ) -> Result<DateTime<Utc>, SchedulerError>
Sourcepub fn register_handler(
&self,
task_id: impl Into<String>,
handler: Arc<dyn JobHandler>,
)
pub fn register_handler( &self, task_id: impl Into<String>, handler: Arc<dyn JobHandler>, )
Registers a JobHandler for the given task id. When the scheduler
fires a matching task, it looks up the handler by task id. If no
handler is registered, the task is skipped silently.
Sourcepub fn try_fire_due(&self, now: DateTime<Utc>) -> usize
pub fn try_fire_due(&self, now: DateTime<Utc>) -> usize
Fires every enabled task whose cron expression matches now. Returns
the number of tasks that fired (and whose handler, if any, returned
Ok(())). Errors from individual handlers are recorded but do not
abort iteration.
Sourcepub fn start(&self, tick_ms: u64) -> Result<(), SchedulerError>
pub fn start(&self, tick_ms: u64) -> Result<(), SchedulerError>
Starts a background worker thread that wakes up every tick_ms
milliseconds, queries the current UTC time, and invokes
try_fire_due. Calling start while a worker is already running
returns an error.
Sourcepub fn stop(&self) -> Result<(), SchedulerError>
pub fn stop(&self) -> Result<(), SchedulerError>
Stops the background worker thread and waits for it to exit. If no worker is running, this is a no-op.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Returns true if a background worker is currently running.
Sourcepub fn try_fire_due_tracked(
&self,
now: DateTime<Utc>,
tracker: &TaskExecutionTracker,
) -> usize
pub fn try_fire_due_tracked( &self, now: DateTime<Utc>, tracker: &TaskExecutionTracker, ) -> usize
Trigger all due tasks and record execution results to tracker.
Difference from try_fire_due: this method records execution status after each task trigger
(Succeeded / Failed / Skipped), for subsequent task health queries.
Sourcepub fn get_task_count(&self) -> usize
pub fn get_task_count(&self) -> usize
Returns total number of registered tasks.
Sourcepub fn get_enabled_task_count(&self) -> usize
pub fn get_enabled_task_count(&self) -> usize
Returns number of enabled tasks.
Sourcepub fn get_task_priorities(&self) -> Vec<(String, i32)>
pub fn get_task_priorities(&self) -> Vec<(String, i32)>
Returns (id, priority) list of all tasks, sorted by priority descending.
Trait Implementations§
Source§impl Default for CronScheduler
impl Default for CronScheduler
Source§fn default() -> CronScheduler
fn default() -> CronScheduler
Source§impl Scheduler for CronScheduler
impl Scheduler for CronScheduler
fn schedule(&self, task: ScheduledTask) -> Result<(), SchedulerError>
fn cancel(&self, task_id: &str) -> Result<(), SchedulerError>
fn pause(&self, task_id: &str) -> Result<(), SchedulerError>
fn resume(&self, task_id: &str) -> Result<(), SchedulerError>
fn list_tasks(&self) -> Vec<ScheduledTask>
Auto Trait Implementations§
impl !Freeze for CronScheduler
impl RefUnwindSafe for CronScheduler
impl Send for CronScheduler
impl Sync for CronScheduler
impl Unpin for CronScheduler
impl UnsafeUnpin for CronScheduler
impl UnwindSafe for CronScheduler
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> ⓘ
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> ⓘ
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