-// If the container is marked as Locked, check if it is already in the slurm
-// queue. If not, submit it.
-//
-// If the container is marked as Running, check if it is in the slurm queue.
-// If not, mark it as Cancelled.
-func monitorSubmitOrCancel(dispatcher *dispatch.Dispatcher, container arvados.Container, monitorDone *bool) {
- submitted := false
- for !*monitorDone {
- if squeueUpdater.CheckSqueue(container.UUID) {
- // Found in the queue, so continue monitoring
- submitted = true
- } else if container.State == dispatch.Locked && !submitted {
- // Not in queue but in Locked state and we haven't
- // submitted it yet, so submit it.
-
- log.Printf("About to submit queued container %v", container.UUID)
-
- if err := submit(dispatcher, container, theConfig.CrunchRunCommand); err != nil {
- log.Printf("Error submitting container %s to slurm: %v",
- container.UUID, err)
- // maybe sbatch is broken, put it back to queued
- dispatcher.Unlock(container.UUID)
- }
- submitted = true
- } else {
- // Not in queue and we are not going to submit it.
- // Refresh the container state. If it is
- // Complete/Cancelled, do nothing, if it is Locked then
- // release it back to the Queue, if it is Running then
- // clean up the record.
-
- var con arvados.Container
- err := dispatcher.Arv.Get("containers", container.UUID, nil, &con)
- if err != nil {
- log.Printf("Error getting final container state: %v", err)
+ // If the container disappears from the slurm queue, there is
+ // no point in waiting for further dispatch updates: just
+ // clean up and return.
+ go func(uuid string) {
+ for ctx.Err() == nil && sqCheck.HasUUID(uuid) {
+ }
+ cancel()
+ }(ctr.UUID)
+
+ for {
+ select {
+ case <-ctx.Done():
+ // Disappeared from squeue
+ if err := disp.Arv.Get("containers", ctr.UUID, nil, &ctr); err != nil {
+ log.Printf("Error getting final container state for %s: %s", ctr.UUID, err)