Skip to content

Commit

Permalink
Add Worker::is_terminated
Browse files Browse the repository at this point in the history
  • Loading branch information
rustworthy committed Sep 19, 2024
1 parent b28bc8d commit 1795c4f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/worker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ impl<E> Worker<E> {
),
}
}

/// Tell if this worker has been terminated.
///
/// Running a terminate worker ([`Worker::run_one`], [`Worker::run`], [`Worker::run_to_completion`])
/// will cause a panic. If the worker is terminated, you will need to build and run a new worker instead.
pub fn is_terminated(&self) -> bool {
self.terminated
}
}

enum Failed<E: StdError, JE: StdError> {
Expand Down Expand Up @@ -323,6 +331,8 @@ impl<E: StdError + 'static + Send> Worker<E> {
/// discontinued due to a signal from the Faktory server or a graceful shutdown signal,
/// calling this method will mean you are trying to run a _terminated_ worker which will
/// cause a panic. You will need to build and run a new worker instead.
///
/// You can check if the worker has been terminated with [`Worker::is_terminated`].
pub async fn run_one<Q>(&mut self, worker: usize, queues: &[Q]) -> Result<bool, Error>
where
Q: AsRef<str> + Sync,
Expand Down Expand Up @@ -430,6 +440,8 @@ impl<E: StdError + 'static + Send> Worker<E> {
/// Note that if you provided a shutdown signal when building this worker (see [`WorkerBuilder::with_graceful_shutdown`]),
/// and this signal resolved, the worker will be marked as terminated and calling this method will cause a panic.
/// You will need to build and run a new worker instead.
///
/// You can check if the worker has been terminated with [`Worker::is_terminated`].
pub async fn run<Q>(&mut self, queues: &[Q]) -> Result<StopDetails, Error>
where
Q: AsRef<str>,
Expand Down
1 change: 1 addition & 0 deletions tests/real/community.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,5 +756,6 @@ async fn test_panic_in_handler() {
.unwrap();

// same for async handler, note how the test run is not interrupted with a panic
assert!(!w.is_terminated());
assert!(w.run_one(0, &[local]).await.unwrap());
}

0 comments on commit 1795c4f

Please sign in to comment.