diff --git a/src/worker/mod.rs b/src/worker/mod.rs index 38398409..bbba6178 100644 --- a/src/worker/mod.rs +++ b/src/worker/mod.rs @@ -210,6 +210,14 @@ impl Worker { ), } } + + /// 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 { @@ -323,6 +331,8 @@ impl Worker { /// 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(&mut self, worker: usize, queues: &[Q]) -> Result where Q: AsRef + Sync, @@ -430,6 +440,8 @@ impl Worker { /// 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(&mut self, queues: &[Q]) -> Result where Q: AsRef, diff --git a/tests/real/community.rs b/tests/real/community.rs index f212d33c..0dfd6363 100644 --- a/tests/real/community.rs +++ b/tests/real/community.rs @@ -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()); }