Merge branch '8784-dir-listings'
[arvados.git] / services / crunch-dispatch-slurm / squeue.go
index 0c90679d3fa6d309655953abadf2bea3c337beee..d22e02597b75d5d5d7a0b74599cc4d142d002345 100644 (file)
@@ -1,3 +1,7 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
 package main
 
 import (
@@ -49,7 +53,7 @@ func (sqc *SqueueChecker) Stop() {
 
 // check gets the names of jobs in the SLURM queue (running and
 // queued). If it succeeds, it updates squeue.uuids and wakes up any
-// goroutines that are waiting in HasUUID().
+// 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
@@ -93,7 +97,16 @@ func (sqc *SqueueChecker) start() {
        }()
 }
 
-// All Uuids in squeue
-func (sqc *SqueueChecker) AllUuids() map[string]bool {
-       return sqc.uuids
+// All waits for the next squeue invocation, and returns all job
+// names reported by squeue.
+func (sqc *SqueueChecker) All() []string {
+       sqc.startOnce.Do(sqc.start)
+       sqc.L.Lock()
+       defer sqc.L.Unlock()
+       sqc.Wait()
+       var uuids []string
+       for uuid := range sqc.uuids {
+               uuids = append(uuids, uuid)
+       }
+       return uuids
 }