-// CheckSqueue checks if a given container UUID is in the slurm queue. This
-// does not run squeue directly, but instead blocks until woken up by next
-// successful update of squeue.
-func (squeue *Squeue) CheckSqueue(uuid string) bool {
- squeue.squeueCond.L.Lock()
- // block until next squeue broadcast signaling an update.
- squeue.squeueCond.Wait()
- contents := squeue.squeueContents
- squeue.squeueCond.L.Unlock()
+// check gets the names of jobs in the SLURM queue (running and
+// queued). If it succeeds, it updates sqc.queue and wakes up any
+// goroutines that are waiting in HasUUID() or All().
+func (sqc *SqueueChecker) check() {
+ // Mutex between squeue sync and running sbatch or scancel. This
+ // establishes a sequence so that squeue doesn't run concurrently with
+ // sbatch or scancel; the next update of squeue will occur only after
+ // sbatch or scancel has completed.
+ sqc.L.Lock()
+ defer sqc.L.Unlock()
+
+ cmd := sqc.Slurm.QueueCommand([]string{"--all", "--format=%j %y %Q"})
+ stdout, stderr := &bytes.Buffer{}, &bytes.Buffer{}
+ cmd.Stdout, cmd.Stderr = stdout, stderr
+ if err := cmd.Run(); err != nil {
+ log.Printf("Error running %q %q: %s %q", cmd.Path, cmd.Args, err, stderr.String())
+ return
+ }