pub enum SchedulerMessage {
Add(Box<TaskDescriptor>),
Cancel(String),
}Expand description
Messages sent to the Scheduler over its control channel.
Obtain the sender from Scheduler::new or Scheduler::with_max_tasks
and use it to add or cancel tasks while the scheduler loop is running.
§Examples
use tokio::sync::watch;
use zeph_scheduler::{JobStore, Scheduler, SchedulerMessage, TaskDescriptor, TaskKind, TaskMode};
use chrono::Utc;
let store = JobStore::open("sqlite:scheduler.db").await?;
let (_shutdown_tx, shutdown_rx) = watch::channel(false);
let (_scheduler, msg_tx) = Scheduler::new(store, shutdown_rx);
// Add a one-shot task that runs immediately.
let desc = TaskDescriptor {
name: "generate-report".into(),
mode: TaskMode::OneShot { run_at: Utc::now() },
kind: TaskKind::Custom("report".into()),
config: serde_json::json!({"task": "Generate weekly report"}),
};
msg_tx.send(SchedulerMessage::Add(Box::new(desc))).await?;
// Cancel a previously registered task.
msg_tx.send(SchedulerMessage::Cancel("generate-report".into())).await?;Variants§
Add(Box<TaskDescriptor>)
Register a new task (or replace an existing one with the same name).
Cancel(String)
Cancel and delete the task with the given name.
Auto Trait Implementations§
impl Freeze for SchedulerMessage
impl RefUnwindSafe for SchedulerMessage
impl Send for SchedulerMessage
impl Sync for SchedulerMessage
impl Unpin for SchedulerMessage
impl UnsafeUnpin for SchedulerMessage
impl UnwindSafe for SchedulerMessage
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