2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-12-27 00:02:19 +08:00

Fix recoverer to run task recovering logic every minute

This commit is contained in:
Ken Hibino 2021-07-04 06:20:36 -07:00
parent d5e9f3b1bd
commit ff6768f9bb

View File

@ -65,14 +65,22 @@ func (r *recoverer) start(wg *sync.WaitGroup) {
timer.Stop() timer.Stop()
return return
case <-timer.C: case <-timer.C:
r.recover()
timer.Reset(r.interval)
}
}
}()
}
func (r *recoverer) recover() {
// Get all tasks which have expired 30 seconds ago or earlier. // Get all tasks which have expired 30 seconds ago or earlier.
deadline := time.Now().Add(-30 * time.Second) deadline := time.Now().Add(-30 * time.Second)
msgs, err := r.broker.ListDeadlineExceeded(deadline, r.queues...) msgs, err := r.broker.ListDeadlineExceeded(deadline, r.queues...)
if err != nil { if err != nil {
r.logger.Warn("recoverer: could not list deadline exceeded tasks") r.logger.Warn("recoverer: could not list deadline exceeded tasks")
continue return
} }
const errMsg = "deadline exceeded" // TODO: better error message const errMsg = "deadline exceeded"
for _, msg := range msgs { for _, msg := range msgs {
if msg.Retried >= msg.Retry { if msg.Retried >= msg.Retry {
r.archive(msg, errMsg) r.archive(msg, errMsg)
@ -80,10 +88,6 @@ func (r *recoverer) start(wg *sync.WaitGroup) {
r.retry(msg, errMsg) r.retry(msg, errMsg)
} }
} }
}
}
}()
} }
func (r *recoverer) retry(msg *base.TaskMessage, errMsg string) { func (r *recoverer) retry(msg *base.TaskMessage, errMsg string) {