pub struct ScheduledTask {
pub name: String,
pub mode: TaskMode,
pub kind: TaskKind,
pub config: Value,
}Expand description
A task held in memory by the crate::Scheduler.
Use ScheduledTask::new / ScheduledTask::periodic for cron-based tasks
and ScheduledTask::oneshot for tasks that run at a fixed point in time.
§Examples
use zeph_scheduler::{ScheduledTask, TaskKind};
let task = ScheduledTask::new(
"daily-cleanup",
"0 3 * * *", // every day at 03:00 UTC (5-field cron)
TaskKind::MemoryCleanup,
serde_json::Value::Null,
)
.expect("valid cron expression");
assert_eq!(task.task_mode_str(), "periodic");
assert!(task.cron_schedule().is_some());Fields§
§name: StringUnique task name used as the primary key in the job store.
mode: TaskModeExecution mode (periodic or one-shot).
kind: TaskKindThe category of work this task performs.
config: ValueArbitrary JSON configuration forwarded to the TaskHandler at execution time.
Implementations§
Source§impl ScheduledTask
impl ScheduledTask
Sourcepub fn new(
name: impl Into<String>,
cron_expr: &str,
kind: TaskKind,
config: Value,
) -> Result<Self, SchedulerError>
pub fn new( name: impl Into<String>, cron_expr: &str, kind: TaskKind, config: Value, ) -> Result<Self, SchedulerError>
Create a new periodic task from a cron expression string.
§Errors
Returns SchedulerError::InvalidCron if the expression is not valid.
Sourcepub fn periodic(
name: impl Into<String>,
cron_expr: &str,
kind: TaskKind,
config: Value,
) -> Result<Self, SchedulerError>
pub fn periodic( name: impl Into<String>, cron_expr: &str, kind: TaskKind, config: Value, ) -> Result<Self, SchedulerError>
Create a periodic task from a cron expression.
§Errors
Returns SchedulerError::InvalidCron if the expression is not valid.
Sourcepub fn oneshot(
name: impl Into<String>,
run_at: DateTime<Utc>,
kind: TaskKind,
config: Value,
) -> Self
pub fn oneshot( name: impl Into<String>, run_at: DateTime<Utc>, kind: TaskKind, config: Value, ) -> Self
Create a one-shot task that runs at a specific point in time.
Sourcepub fn cron_schedule(&self) -> Option<&CronSchedule>
pub fn cron_schedule(&self) -> Option<&CronSchedule>
Returns the cron schedule if this is a periodic task.
Sourcepub fn cron_expr_string(&self) -> String
pub fn cron_expr_string(&self) -> String
Returns the canonical 6-field cron expression string for DB persistence.
Returns an empty string for one-shot tasks, which do not have a cron schedule.
Sourcepub fn task_mode_str(&self) -> &'static str
pub fn task_mode_str(&self) -> &'static str
Returns the task_mode string used for DB persistence.
Returns "periodic" or "oneshot".
Auto Trait Implementations§
impl Freeze for ScheduledTask
impl RefUnwindSafe for ScheduledTask
impl Send for ScheduledTask
impl Sync for ScheduledTask
impl Unpin for ScheduledTask
impl UnsafeUnpin for ScheduledTask
impl UnwindSafe for ScheduledTask
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
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