for item := range nextItem {
pullRequest := item.(PullRequest)
err := PullItemAndProcess(item.(PullRequest), GenerateRandomApiToken(), keepClient)
- pullq.ReportDone <- struct{}{}
+ pullq.DoneItem <- struct{}{}
if err == nil {
log.Printf("Pull %s success", pullRequest)
} else {
for item := range trashq.NextItem {
trashRequest := item.(TrashRequest)
TrashItem(trashRequest)
- trashq.ReportDone <- struct{}{}
+ trashq.DoneItem <- struct{}{}
}
}
newlist chan *list.List
// Workers get work items by reading from this channel.
NextItem <-chan interface{}
- // Each worker must send struct{}{} to ReportDone exactly once
+ // Each worker must send struct{}{} to DoneItem exactly once
// for each work item received from NextItem, when it stops
// working on that item (regardless of whether the work was
// successful).
- ReportDone chan<- struct{}
+ DoneItem chan<- struct{}
}
type WorkQueueStatus struct {
reportDone := make(chan struct{})
newList := make(chan *list.List)
b := WorkQueue{
- getStatus: make(chan WorkQueueStatus),
- newlist: newList,
- NextItem: nextItem,
- ReportDone: reportDone,
+ getStatus: make(chan WorkQueueStatus),
+ newlist: newList,
+ NextItem: nextItem,
+ DoneItem: reportDone,
}
go func() {
// Read new work lists from the newlist channel.
if !ok {
t.Fatalf("Expected %+v but channel was closed after receiving %+v as expected.", expected, expected[:i])
}
- q.ReportDone <- struct{}{}
+ q.DoneItem <- struct{}{}
if actual.(int) != expected[i] {
t.Fatalf("Expected %+v but received %+v after receiving %+v as expected.", expected[i], actual, expected[:i])
}
for _ = range b.NextItem {
<-gate
time.Sleep(time.Millisecond)
- b.ReportDone <- struct{}{}
+ b.DoneItem <- struct{}{}
}
}()
expectEqualWithin(t, time.Second, 0, func() interface{} { return b.Status().InProgress })
<-b.NextItem
mark <- struct{}{}
<-mark
- b.ReportDone <- struct{}{}
+ b.DoneItem <- struct{}{}
}()
b.ReplaceQueue(makeTestWorkList(input))
// Wait for worker to take item 1