// Cancel cancels the given container.
func (cq *Queue) Cancel(uuid string) error {
- err := cq.client.RequestAndDecode(nil, "PUT", "arvados/v1/containers/"+uuid, nil, map[string]map[string]interface{}{
+ var resp arvados.Container
+ err := cq.client.RequestAndDecode(&resp, "PUT", "arvados/v1/containers/"+uuid, nil, map[string]map[string]interface{}{
"container": {"state": arvados.ContainerStateCancelled},
})
if err != nil {
return err
}
- cq.mtx.Lock()
- defer cq.mtx.Unlock()
- cq.notify()
+ cq.updateWithResp(uuid, resp)
return nil
}
if err != nil {
return err
}
+ cq.updateWithResp(uuid, resp)
+ return nil
+}
+// Update the local queue with the response received from a
+// state-changing API request (lock/unlock/cancel).
+func (cq *Queue) updateWithResp(uuid string, resp arvados.Container) {
cq.mtx.Lock()
defer cq.mtx.Unlock()
if cq.dontupdate != nil {
cq.current[uuid] = ent
}
cq.notify()
- return nil
}
func (cq *Queue) poll() (map[string]*arvados.Container, error) {
defer wg.Done()
err := cq.Unlock(uuid)
c.Check(err, check.NotNil)
+
err = cq.Lock(uuid)
c.Check(err, check.IsNil)
ctr, ok := cq.Get(uuid)
c.Check(ctr.State, check.Equals, arvados.ContainerStateLocked)
err = cq.Lock(uuid)
c.Check(err, check.NotNil)
+
err = cq.Unlock(uuid)
c.Check(err, check.IsNil)
ctr, ok = cq.Get(uuid)
c.Check(ctr.State, check.Equals, arvados.ContainerStateQueued)
err = cq.Unlock(uuid)
c.Check(err, check.NotNil)
+
+ err = cq.Cancel(uuid)
+ c.Check(err, check.IsNil)
+ ctr, ok = cq.Get(uuid)
+ c.Check(ok, check.Equals, true)
+ c.Check(ctr.State, check.Equals, arvados.ContainerStateCancelled)
+ err = cq.Lock(uuid)
+ c.Check(err, check.NotNil)
}()
}
wg.Wait()