提交 2b2dbe72 authored 作者: Serhij S's avatar Serhij S

shutdown methods

上级 79fb7822
...@@ -7,6 +7,9 @@ use signal_hook::{ ...@@ -7,6 +7,9 @@ use signal_hook::{
}; };
use tracing::info; use tracing::info;
// The maximum shutdown time
const SHUTDOWN_TIMEOUT: Duration = Duration::from_secs(2);
#[derive(DataPolicy, Clone)] #[derive(DataPolicy, Clone)]
enum Message { enum Message {
Data(u8), Data(u8),
...@@ -73,9 +76,9 @@ impl Worker<Message, ()> for SignalHandler { ...@@ -73,9 +76,9 @@ impl Worker<Message, ()> for SignalHandler {
// it is really important to set max shutdown timeout for the controller if the // it is really important to set max shutdown timeout for the controller if the
// controller does not terminate in the given time, the process and all its // controller does not terminate in the given time, the process and all its
// sub-processes are forcibly killed // sub-processes are forcibly killed
suicide(Duration::from_secs(2), true); suicide(SHUTDOWN_TIMEOUT, true);
// set controller state to terminating // set controller state to Stopping
context.set_state(ControllerStateKind::Stopping); context.terminate();
// send Terminate message to workers who listen to the hub // send Terminate message to workers who listen to the hub
context.hub().send(Message::Terminate); context.hub().send(Message::Terminate);
} }
......
...@@ -187,6 +187,10 @@ where ...@@ -187,6 +187,10 @@ where
pub fn is_online(&self) { pub fn is_online(&self) {
self.state.is_online(); self.state.is_online();
} }
/// Sets controller state to Stopping
pub fn terminate(&mut self) {
self.state.set(ControllerStateKind::Stopping);
}
/// State beacon /// State beacon
pub fn state(&self) -> &State { pub fn state(&self) -> &State {
&self.state &self.state
...@@ -252,6 +256,10 @@ where ...@@ -252,6 +256,10 @@ where
pub fn is_online(&self) -> bool { pub fn is_online(&self) -> bool {
self.state.is_online() self.state.is_online()
} }
/// Sets controller state to Stopping
pub fn terminate(&self) {
self.state.set(ControllerStateKind::Stopping);
}
} }
/// The trait which MUST be implemented by all workers /// The trait which MUST be implemented by all workers
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论