gapi: Move separate etcd Watch method into GAPI

This cleans up the API to not have a special case for etcd anymore. In
particular, this also adds the requirement that the GAPI must generate
an event on startup as soon as it is ready to generate a graph.
This commit is contained in:
James Shubin
2017-03-20 15:10:27 -04:00
parent 66d9c7091c
commit 6fd5623b1f
6 changed files with 62 additions and 40 deletions

View File

@@ -91,21 +91,27 @@ func (obj *GAPI) Next() chan error {
ch <- fmt.Errorf("the puppet GAPI is not initialized")
return
}
startChan := make(chan struct{}) // start signal
close(startChan) // kick it off!
pChan := puppetChan()
for {
select {
case <-startChan: // kick the loop once at start
startChan = nil // disable
// pass
case _, ok := <-pChan:
if !ok { // the channel closed!
return
}
log.Printf("Puppet: Generating new graph...")
pChan = puppetChan() // TODO: okay to update interval in case it changed?
select {
case ch <- nil: // trigger a run (send a msg)
// unblock if we exit while waiting to send!
case <-obj.closeChan:
return
}
case <-obj.closeChan:
return
}
log.Printf("Puppet: Generating new graph...")
pChan = puppetChan() // TODO: okay to update interval in case it changed?
select {
case ch <- nil: // trigger a run (send a msg)
// unblock if we exit while waiting to send!
case <-obj.closeChan:
return
}