2
0
mirror of https://github.com/hibiken/asynq.git synced 2026-02-02 05:46:53 +00:00

Add logic to restore unfinished tasks back into the default queue if

there are any uncompleted tasks
This commit is contained in:
Ken Hibino
2019-11-23 15:09:50 -08:00
parent 4a327933bd
commit fd80126a67
3 changed files with 71 additions and 12 deletions

View File

@@ -41,6 +41,9 @@ func (p *processor) terminate() {
}
func (p *processor) start() {
// NOTE: The call to "restore" needs to complete before starting
// the processor goroutine.
p.restore()
go func() {
for {
select {
@@ -92,3 +95,12 @@ func (p *processor) exec() {
}
}(task)
}
// restore moves all tasks from "in-progress" back to queue
// to restore all unfinished tasks.
func (p *processor) restore() {
err := p.rdb.moveAll(inProgress, defaultQueue)
if err != nil {
log.Printf("[SERVER ERROR] could not move tasks from %q to %q\n", inProgress, defaultQueue)
}
}