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

shutdown methods

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