WorkerTaskContext: add shutdown_requested() and fail_on_shutdown()
This commit is contained in:
@ -16,6 +16,19 @@ pub trait WorkerTaskContext {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Test if there was a request to shutdown the server.
|
||||
fn shutdown_requested(&self) -> bool;
|
||||
|
||||
|
||||
/// This should fail with a reasonable error message if there was
|
||||
/// a request to shutdown the server.
|
||||
fn fail_on_shutdown(&self) -> Result<(), Error> {
|
||||
if self.shutdown_requested() {
|
||||
bail!("Server shutdown requested - aborting task");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Create a log message for this task.
|
||||
fn log(&self, level: log::Level, message: &std::fmt::Arguments);
|
||||
}
|
||||
@ -30,6 +43,14 @@ impl<T: WorkerTaskContext + ?Sized> WorkerTaskContext for std::sync::Arc<T> {
|
||||
<T as WorkerTaskContext>::check_abort(&*self)
|
||||
}
|
||||
|
||||
fn shutdown_requested(&self) -> bool {
|
||||
<T as WorkerTaskContext>::shutdown_requested(&*self)
|
||||
}
|
||||
|
||||
fn fail_on_shutdown(&self) -> Result<(), Error> {
|
||||
<T as WorkerTaskContext>::fail_on_shutdown(&*self)
|
||||
}
|
||||
|
||||
fn log(&self, level: log::Level, message: &std::fmt::Arguments) {
|
||||
<T as WorkerTaskContext>::log(&*self, level, message)
|
||||
}
|
||||
|
Reference in New Issue
Block a user