Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide worker and scheduler shutdown methods #36

Merged
merged 1 commit into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ impl<T: Task> Scheduler<T> {
}
}

/// 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 {
Expand Down
9 changes: 9 additions & 0 deletions src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@ impl<T: Task + Sync> Worker<T> {
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
Expand Down