1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-23 21:51:06 +01:00

Add ServerWorker::restart_service method (#314)

Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
fakeshadow 2021-04-04 05:22:34 -07:00 committed by GitHub
parent 05689b86d9
commit 8079c50ddb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -262,6 +262,13 @@ impl ServerWorker {
WorkerHandle::new(idx, tx1, tx2, avail)
}
fn restart_service(&mut self, token: Token, idx: usize) {
let factory = &self.factories[idx];
trace!("Service {:?} failed, restarting", factory.name(token));
self.services[token.0].status = WorkerServiceStatus::Restarting;
self.state = WorkerState::Restarting(idx, token, factory.create());
}
fn shutdown(&mut self, force: bool) {
self.services
.iter_mut()
@ -376,13 +383,7 @@ impl Future for ServerWorker {
}
Ok(false) => Poll::Pending,
Err((token, idx)) => {
trace!(
"Service {:?} failed, restarting",
self.factories[idx].name(token)
);
self.services[token.0].status = WorkerServiceStatus::Restarting;
self.state =
WorkerState::Restarting(idx, token, self.factories[idx].create());
self.restart_service(token, idx);
self.poll(cx)
}
},
@ -437,7 +438,7 @@ impl Future for ServerWorker {
// actively poll stream and handle worker command
WorkerState::Available => loop {
match self.check_readiness(cx) {
Ok(true) => (),
Ok(true) => {}
Ok(false) => {
trace!("Worker is unavailable");
self.availability.set(false);
@ -445,14 +446,8 @@ impl Future for ServerWorker {
return self.poll(cx);
}
Err((token, idx)) => {
trace!(
"Service {:?} failed, restarting",
self.factories[idx].name(token)
);
self.restart_service(token, idx);
self.availability.set(false);
self.services[token.0].status = WorkerServiceStatus::Restarting;
self.state =
WorkerState::Restarting(idx, token, self.factories[idx].create());
return self.poll(cx);
}
}