X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/ff8c3cfde1e73c1c0adccb670040e98d82120e99..0020a0bc96ee13203fbdc2af28ffa077799213d0:/lib/dispatchcloud/test/queue.go diff --git a/lib/dispatchcloud/test/queue.go b/lib/dispatchcloud/test/queue.go index fda04d52b3..6a6c952358 100644 --- a/lib/dispatchcloud/test/queue.go +++ b/lib/dispatchcloud/test/queue.go @@ -95,6 +95,7 @@ func (q *Queue) Unsubscribe(ch <-chan struct{}) { delete(q.subscribers, ch) } +// caller must have lock. func (q *Queue) notify() { for _, ch := range q.subscribers { select { @@ -133,10 +134,15 @@ func (q *Queue) Update() error { if !exists && (ctr.State == arvados.ContainerStateComplete || ctr.State == arvados.ContainerStateCancelled) { continue } - it, _ := q.ChooseType(&ctr) - upd[ctr.UUID] = container.QueueEnt{ - Container: ctr, - InstanceType: it, + if ent, ok := upd[ctr.UUID]; ok { + ent.Container = ctr + upd[ctr.UUID] = ent + } else { + it, _ := q.ChooseType(&ctr) + upd[ctr.UUID] = container.QueueEnt{ + Container: ctr, + InstanceType: it, + } } } q.entries = upd @@ -152,14 +158,21 @@ func (q *Queue) Update() error { // // The resulting changes are not exposed through Get() or Entries() // until the next call to Update(). -func (q *Queue) Notify(upd arvados.Container) { +// +// Return value is true unless the update is rejected (invalid state +// transition). +func (q *Queue) Notify(upd arvados.Container) bool { q.mtx.Lock() defer q.mtx.Unlock() for i, ctr := range q.Containers { if ctr.UUID == upd.UUID { - q.Containers[i] = upd - return + if ctr.State != arvados.ContainerStateComplete && ctr.State != arvados.ContainerStateCancelled { + q.Containers[i] = upd + return true + } + return false } } q.Containers = append(q.Containers, upd) + return true }