-// 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, error) {
- squeue.squeueCond.L.Lock()
- // block until next squeue broadcast signaling an update.
- squeue.squeueCond.Wait()
- if squeue.squeueError != nil {
- e := squeue.squeueError
- squeue.squeueCond.L.Unlock()
- return false, e
- }
- contents := squeue.squeueContents
- squeue.squeueCond.L.Unlock()
-
- for _, k := range contents {
- if k == uuid {
- return true, nil
+// Initialize, and start a goroutine to call check() once per
+// squeue.Period until terminated by calling Stop().
+func (sqc *SqueueChecker) start() {
+ sqc.L = &sync.Mutex{}
+ sqc.done = make(chan struct{})
+ go func() {
+ ticker := time.NewTicker(sqc.Period)
+ for {
+ select {
+ case <-sqc.done:
+ ticker.Stop()
+ return
+ case <-ticker.C:
+ sqc.check()
+ }