diff --git a/src/scheduler.rs b/src/scheduler.rs index c6faaca..fb7dce6 100644 --- a/src/scheduler.rs +++ b/src/scheduler.rs @@ -63,6 +63,11 @@ impl Scheduler { } } + /// Cancels the shutdown token causing the scheduler to exit. + pub fn shutdown(&self) { + self.shutdown_token.cancel(); + } + /// Loops over the configured schedule, enqueuing tasks as the duration /// arrives. pub async fn run(&self) -> Result { diff --git a/src/worker.rs b/src/worker.rs index fcf9621..c2c1cb3 100644 --- a/src/worker.rs +++ b/src/worker.rs @@ -203,6 +203,15 @@ impl Worker { self } + /// Cancels the shutdown token and begins a graceful shutdown of in-progress + /// tasks. + /// + /// Note that tasks are given until their configured timeout to complete + /// before the worker will exit. + pub fn shutdown(&self) { + self.shutdown_token.cancel(); + } + /// Runs the worker, processing tasks as they become available. /// /// Tasks are processed via a subscription to a Postgres channel and polling