@@ -262,6 +262,13 @@ impl ServerWorker {
262
262
WorkerHandle :: new ( idx, tx1, tx2, avail)
263
263
}
264
264
265
+ fn restart_service ( & mut self , token : Token , idx : usize ) {
266
+ let factory = & self . factories [ idx] ;
267
+ trace ! ( "Service {:?} failed, restarting" , factory. name( token) ) ;
268
+ self . services [ token. 0 ] . status = WorkerServiceStatus :: Restarting ;
269
+ self . state = WorkerState :: Restarting ( idx, token, factory. create ( ) ) ;
270
+ }
271
+
265
272
fn shutdown ( & mut self , force : bool ) {
266
273
self . services
267
274
. iter_mut ( )
@@ -376,13 +383,7 @@ impl Future for ServerWorker {
376
383
}
377
384
Ok ( false ) => Poll :: Pending ,
378
385
Err ( ( token, idx) ) => {
379
- trace ! (
380
- "Service {:?} failed, restarting" ,
381
- self . factories[ idx] . name( token)
382
- ) ;
383
- self . services [ token. 0 ] . status = WorkerServiceStatus :: Restarting ;
384
- self . state =
385
- WorkerState :: Restarting ( idx, token, self . factories [ idx] . create ( ) ) ;
386
+ self . restart_service ( token, idx) ;
386
387
self . poll ( cx)
387
388
}
388
389
} ,
@@ -437,22 +438,16 @@ impl Future for ServerWorker {
437
438
// actively poll stream and handle worker command
438
439
WorkerState :: Available => loop {
439
440
match self . check_readiness ( cx) {
440
- Ok ( true ) => ( ) ,
441
+ Ok ( true ) => { }
441
442
Ok ( false ) => {
442
443
trace ! ( "Worker is unavailable" ) ;
443
444
self . availability . set ( false ) ;
444
445
self . state = WorkerState :: Unavailable ;
445
446
return self . poll ( cx) ;
446
447
}
447
448
Err ( ( token, idx) ) => {
448
- trace ! (
449
- "Service {:?} failed, restarting" ,
450
- self . factories[ idx] . name( token)
451
- ) ;
449
+ self . restart_service ( token, idx) ;
452
450
self . availability . set ( false ) ;
453
- self . services [ token. 0 ] . status = WorkerServiceStatus :: Restarting ;
454
- self . state =
455
- WorkerState :: Restarting ( idx, token, self . factories [ idx] . create ( ) ) ;
456
451
return self . poll ( cx) ;
457
452
}
458
453
}
0 commit comments