1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-02-17 14:43:31 +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) 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) { fn shutdown(&mut self, force: bool) {
self.services self.services
.iter_mut() .iter_mut()
@ -376,13 +383,7 @@ impl Future for ServerWorker {
} }
Ok(false) => Poll::Pending, Ok(false) => Poll::Pending,
Err((token, idx)) => { Err((token, idx)) => {
trace!( self.restart_service(token, idx);
"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.poll(cx) self.poll(cx)
} }
}, },
@ -437,7 +438,7 @@ impl Future for ServerWorker {
// actively poll stream and handle worker command // actively poll stream and handle worker command
WorkerState::Available => loop { WorkerState::Available => loop {
match self.check_readiness(cx) { match self.check_readiness(cx) {
Ok(true) => (), Ok(true) => {}
Ok(false) => { Ok(false) => {
trace!("Worker is unavailable"); trace!("Worker is unavailable");
self.availability.set(false); self.availability.set(false);
@ -445,14 +446,8 @@ impl Future for ServerWorker {
return self.poll(cx); return self.poll(cx);
} }
Err((token, idx)) => { Err((token, idx)) => {
trace!( self.restart_service(token, idx);
"Service {:?} failed, restarting",
self.factories[idx].name(token)
);
self.availability.set(false); 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); return self.poll(cx);
} }
} }