Merge branch 'master' of git.curoverse.com:arvados into 13076-r-autogen-api
[arvados.git] / services / crunch-dispatch-slurm / squeue.go
index d15489b278ec6e84c17f944d9e463920e3e17cb0..b8e3108c7c1a235e7c7e28ffc10974652a35cc6a 100644 (file)
@@ -51,17 +51,19 @@ func (sqc *SqueueChecker) HasUUID(uuid string) bool {
 // SetPriority sets or updates the desired (Arvados) priority for a
 // container.
 func (sqc *SqueueChecker) SetPriority(uuid string, want int64) {
+       sqc.startOnce.Do(sqc.start)
        sqc.L.Lock()
        defer sqc.L.Unlock()
-       if _, ok := sqc.queue[uuid]; !ok {
+       job, ok := sqc.queue[uuid]
+       if !ok {
                // Wait in case the slurm job was just submitted and
                // will appear in the next squeue update.
                sqc.Wait()
-               if _, ok = sqc.queue[uuid]; !ok {
+               if job, ok = sqc.queue[uuid]; !ok {
                        return
                }
        }
-       sqc.queue[uuid].wantPriority = want
+       job.wantPriority = want
 }
 
 // adjust slurm job nice values as needed to ensure slurm priority
@@ -132,11 +134,13 @@ func (sqc *SqueueChecker) check() {
                        log.Printf("warning: ignoring unparsed line in squeue output: %q", line)
                        continue
                }
-               newq[uuid] = &slurmJob{
-                       uuid:     uuid,
-                       priority: p,
-                       nice:     n,
+               replacing, ok := sqc.queue[uuid]
+               if !ok {
+                       replacing = &slurmJob{uuid: uuid}
                }
+               replacing.priority = p
+               replacing.nice = n
+               newq[uuid] = replacing
        }
        sqc.queue = newq
        sqc.Broadcast()