"time"
)
+// Squeue implements asynchronous polling monitor of the SLURM queue using the
+// command 'squeue'.
type Squeue struct {
squeueContents []string
squeueDone chan struct{}
var squeueCmd = squeueFunc
+// RunSqueue runs squeue once and captures the output. If there is an error,
+// set "squeueError". If it succeeds, set "squeueContents" and then wake up
+// any goroutines waiting squeueCond in CheckSqueue().
func (squeue *Squeue) RunSqueue() error {
var newSqueueContents []string
return nil
}
-// Check if a container UUID is in the slurm queue. This will block until the
-// next successful update from SLURM.
+// 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) {
squeueUpdater.squeueCond.L.Lock()
// block until next squeue broadcast signaling an update.
return false, nil
}
+// StartMonitor starts the squeue monitoring goroutine.
func (squeue *Squeue) StartMonitor(pollInterval time.Duration) {
squeueUpdater.squeueCond = sync.NewCond(&sync.Mutex{})
squeueUpdater.squeueDone = make(chan struct{})
go squeueUpdater.SyncSqueue(pollInterval)
}
+// Done stops the squeue monitoring goroutine.
func (squeue *Squeue) Done() {
squeueUpdater.squeueDone <- struct{}{}
close(squeueUpdater.squeueDone)
}
+// SyncSqueue periodically polls RunSqueue() at the given duration until
+// terminated by calling Done().
func (squeue *Squeue) SyncSqueue(pollInterval time.Duration) {
ticker := time.NewTicker(pollInterval)
for {