"bytes"
"fmt"
"log"
- "os/exec"
"strings"
"sync"
"time"
)
+type jobPriority struct {
+ niceness int
+ currentPriority int
+}
+
// Squeue implements asynchronous polling monitor of the SLURM queue using the
// command 'squeue'.
type SqueueChecker struct {
Period time.Duration
- uuids map[string]int
+ Slurm Slurm
+ uuids map[string]jobPriority
startOnce sync.Once
done chan struct{}
sync.Cond
}
-func squeueFunc() *exec.Cmd {
- return exec.Command("squeue", "--all", "--format=%j %y")
-}
-
-var squeueCmd = squeueFunc
-
// HasUUID 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.
n, exists := sqc.uuids[uuid]
if exists {
- return n
+ return n.niceness
} else {
return -1
}
sqc.L.Lock()
defer sqc.L.Unlock()
- cmd := squeueCmd()
+ 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 {
}
lines := strings.Split(stdout.String(), "\n")
- sqc.uuids = make(map[string]int, len(lines))
+ sqc.uuids = make(map[string]jobPriority, len(lines))
for _, line := range lines {
var uuid string
var nice int
- fmt.Sscan(line, &uuid, &nice)
+ var prio int
+ fmt.Sscan(line, &uuid, &nice, &prio)
if uuid != "" {
- sqc.uuids[uuid] = nice
+ sqc.uuids[uuid] = jobPriority{nice, prio}
}
}
sqc.Broadcast()