gapi: Allow the GAPI implementer to specify fast and exit

This allows the implementer of the GAPI to specify three parameters for
every Next message sent on the channel. The Fast parameter tells the
agent if it should do the pause quickly or if it should finish the
sequence. A quick pause means that it will cause a pause immediately
after the currently running resources finish, where as a slow (default)
pause will allow the wave of execution to finish. This is usually
preferred in scenarios where complex graphs are used where we want each
step to complete. The Exit parameter tells the engine to exit, and the
Err parameter tells the engine that an error occurred.
This commit is contained in:
James Shubin
2017-06-02 03:39:42 -04:00
parent 9531465410
commit 9cbaa892d3
12 changed files with 129 additions and 61 deletions

View File

@@ -83,15 +83,18 @@ func (obj *MyGAPI) Graph() (*pgraph.Graph, error) {
}
// Next returns nil errors every time there could be a new graph.
func (obj *MyGAPI) Next() chan error {
ch := make(chan error)
func (obj *MyGAPI) Next() chan gapi.Next {
ch := make(chan gapi.Next)
obj.wg.Add(1)
go func() {
defer obj.wg.Done()
defer close(ch) // this will run before the obj.wg.Done()
if !obj.initialized {
ch <- fmt.Errorf("libmgmt: MyGAPI is not initialized")
return
next := gapi.Next{
Err: fmt.Errorf("libmgmt: MyGAPI is not initialized"),
Exit: true, // exit, b/c programming error?
}
ch <- next
}
startChan := make(chan struct{}) // start signal
close(startChan) // kick it off!
@@ -118,7 +121,7 @@ func (obj *MyGAPI) Next() chan error {
log.Printf("libmgmt: Generating new graph...")
select {
case ch <- nil: // trigger a run
case ch <- gapi.Next{}: // trigger a run
case <-obj.closeChan:
return
}