1
0
Fork 0

Handle worker crashes

This commit is contained in:
Gregory Eremin 2015-10-24 18:49:38 +03:00
parent 2ebd972a34
commit 4465d2c561
1 changed files with 9 additions and 1 deletions

View File

@ -138,7 +138,14 @@ func (s *Satan) runWorker() {
i := atomic.AddUint64(&workerIndex, 1)
log.Printf("Starting worker #%d", i)
defer log.Printf("Worker #%d has stopped", i)
defer func() {
if err := recover(); err != nil {
log.Printf("Worker #%d crashed. Error: %v\n", i, err)
debug.PrintStack()
go s.runWorker() // Restarting worker
}
}()
for {
start := time.Now()
@ -148,6 +155,7 @@ func (s *Satan) runWorker() {
s.Statistics.Add("TaskWait", time.Duration(dur))
s.processTask(t)
case <-s.shutdownWorkers:
log.Printf("Worker #%d has stopped", i)
return
}
}