Add IsOrphaned field to TaskInfo

This commit is contained in:
Ken Hibino
2022-02-18 20:50:18 -08:00
parent 9b63e23274
commit cea5110d15
4 changed files with 66 additions and 4 deletions

View File

@@ -308,16 +308,28 @@ func (i *Inspector) ListActiveTasks(qname string, opts ...ListOption) ([]*TaskIn
case err != nil:
return nil, fmt.Errorf("asynq: %v", err)
}
expired, err := i.rdb.ListLeaseExpired(time.Now(), qname)
if err != nil {
return nil, fmt.Errorf("asynq: %v", err)
}
expiredSet := make(map[string]struct{}) // set of expired message IDs
for _, msg := range expired {
expiredSet[msg.ID] = struct{}{}
}
var tasks []*TaskInfo
for _, i := range infos {
tasks = append(tasks, newTaskInfo(
t := newTaskInfo(
i.Message,
i.State,
i.NextProcessAt,
i.Result,
))
)
if _, ok := expiredSet[i.Message.ID]; ok {
t.IsOrphaned = true
}
tasks = append(tasks, t)
}
return tasks, err
return tasks, nil
}
// ListScheduledTasks retrieves scheduled tasks from the specified queue.