// Remove a task from a queue // If dontDelete (single extra arg) is true, then no delete call will be done for the task func (q *Queue) Remove(subq *simpleq.Queue, task Task, keepInStorage ...bool) error { id := q.id(task) w := waiter.New(2) go func() { if len(keepInStorage) > 0 && keepInStorage[0] { if err := q.Storage.Set(map[string]interface{}(task), id); err != nil { w.Errors <- err } } else { if err := q.Storage.Del(id); err != nil { w.Errors <- err } } w.Done <- true }() go func() { if n, err := subq.Pull([]byte(id)); err != nil { w.Errors <- err } else if n == 0 { w.Errors <- errors.New("Task " + id + " not found in queue.") } w.Done <- true }() return w.Wait() }
// Remove a task from a queue // If dontDelete (single extra arg) is true, then no delete call will be done for the task func (q *Queue) Remove(subq *simpleq.Queue, task Ider, keepInStorage ...bool) error { id := task.Id() w := waiter.New(2) go func() { if len(keepInStorage) > 0 && keepInStorage[0] { if err := q.Storage.Set(task, id); err != nil { w.Errors <- err } } else { if err := q.Storage.Del(id); err != nil { w.Errors <- err } } w.Done <- true }() go func() { if n, err := subq.Pull(id); err != nil { w.Errors <- err } else if n == 0 { w.Errors <- fmt.Errorf("Task %s not found in queue.", id) } w.Done <- true }() return w.Wait() }
func checkList(t *testing.T, rq *Queue, sq *simpleq.Queue, els ...Task) { list, err := sq.List() if err != nil { t.Error("Error List(): " + err.Error()) } if len(list) == 0 && len(els) == 0 { return } if len(list) != len(els) { t.Error("List isn't the same length as els") return } for i, id := range list { el, err := rq.Storage.Get(string(id)) if err != nil { t.Error("Error doing storage.Get(): ", err, string(id)) continue } checkTaskEqual(t, Task(el), els[i]) } }