pgraph, resources: Improve Init/Close and Worker status

This should do some rough cleanups around the Init/Close of resources,
and tracking of Worker function status.
This commit is contained in:
James Shubin
2017-02-02 19:48:42 -05:00
parent bec7f1726f
commit 2da21f90f4
5 changed files with 54 additions and 34 deletions

View File

@@ -316,7 +316,11 @@ func (g *Graph) Worker(v *Vertex) error {
// the Watch() function about which graph it is
// running on, which isolates things nicely...
obj := v.Res
obj.SetWorking(true) // gets set to false in Res.Close() method at end...
// run the init (should match 1-1 with Close function if this succeeds)
if err := obj.Init(); err != nil {
return errwrap.Wrapf(err, "could not Init() resource")
}
lock := &sync.Mutex{} // lock around processChan closing and sending
finished := false // did we close processChan ?
@@ -629,7 +633,7 @@ func (g *Graph) Start(first bool) { // start or continue
go func(vv *Vertex) {
defer g.wg.Done()
// TODO: if a sufficient number of workers error,
// should something be done? Will these restart
// should something be done? Should these restart
// after perma-failure if we have a graph change?
if err := g.Worker(vv); err != nil { // contains the Watch and CheckApply loops
log.Printf("%s[%s]: Exited with failure: %v", vv.Kind(), vv.GetName(), err)