}
tracker.updates <- c
}
+
+// Start a tracker for the given uuid if one is not already existing, despite its state.
+// its vs. it's -- episode 5 from Series 1 of Netflix' "A Series of Unfortunate Events"
+func (dispatcher *Dispatcher) TrackContainer(uuid string) {
+}
"math"
"os"
"os/exec"
+ "regexp"
"strings"
"time"
log.Printf("Error notifying init daemon: %v", err)
}
+ containerTrackerTicker := trackContainers(dispatcher)
+ defer containerTrackerTicker.Stop()
+
return dispatcher.Run(context.Background())
}
+var containerUuidPattern = regexp.MustCompile(`[a-z0-9]{5}-dz642-[a-z0-9]{15}$`)
+
+// Start a goroutine to check squeue report periodically, and
+// invoke TrackContainer for all the containers in the report.
+func trackContainers(dispatcher *dispatch.Dispatcher) *time.Ticker {
+ ticker := time.NewTicker(sqCheck.Period)
+ go func() {
+ for {
+ select {
+ case <-ticker.C:
+ for uuid := range sqCheck.AllUuids() {
+ match := containerUuidPattern.MatchString(uuid)
+ if match {
+ dispatcher.TrackContainer(uuid)
+ }
+ }
+ }
+ }
+ }()
+ return ticker
+}
+
// sbatchCmd
func sbatchFunc(container arvados.Container) *exec.Cmd {
memPerCPU := math.Ceil(float64(container.RuntimeConstraints.RAM) / (float64(container.RuntimeConstraints.VCPUs) * 1048576))
// command 'squeue'.
type SqueueChecker struct {
Period time.Duration
- hasUUID map[string]bool
+ uuids map[string]bool
startOnce sync.Once
done chan struct{}
sync.Cond
// block until next squeue broadcast signaling an update.
sqc.Wait()
- return sqc.hasUUID[uuid]
+ return sqc.uuids[uuid]
}
// Stop stops the squeue monitoring goroutine. Do not call HasUUID
}
// check gets the names of jobs in the SLURM queue (running and
-// queued). If it succeeds, it updates squeue.hasUUID and wakes up any
+// queued). If it succeeds, it updates squeue.uuids and wakes up any
// goroutines that are waiting in HasUUID().
func (sqc *SqueueChecker) check() {
// Mutex between squeue sync and running sbatch or scancel. This
}
uuids := strings.Split(stdout.String(), "\n")
- sqc.hasUUID = make(map[string]bool, len(uuids))
+ sqc.uuids = make(map[string]bool, len(uuids))
for _, uuid := range uuids {
- sqc.hasUUID[uuid] = true
+ sqc.uuids[uuid] = true
}
sqc.Broadcast()
}
}
}()
}
+
+// All Uuids in squeue
+func (sqc *SqueueChecker) AllUuids() map[string]bool {
+ return sqc.uuids
+}