resources: Simplify resource Converger and Startup code
This takes the Converged initialization and Startup patterns that are common in all resources, and bakes it into the core engine. This way resource writing is much more concise and there is less boilerplate!
This commit is contained in:
@@ -137,17 +137,7 @@ func (obj *VirtRes) Watch(processChan chan event.Event) error {
|
||||
}
|
||||
obj.SetWatching(true)
|
||||
defer obj.SetWatching(false)
|
||||
cuid := obj.converger.Register()
|
||||
defer cuid.Unregister()
|
||||
|
||||
var startup bool
|
||||
Startup := func(block bool) <-chan time.Time {
|
||||
if block {
|
||||
return nil // blocks forever
|
||||
//return make(chan time.Time) // blocks forever
|
||||
}
|
||||
return time.After(time.Duration(500) * time.Millisecond) // 1/2 the resolution of converged timeout
|
||||
}
|
||||
cuid := obj.Converger() // get the converger uid used to report status
|
||||
|
||||
conn, err := obj.connect()
|
||||
if err != nil {
|
||||
@@ -203,6 +193,11 @@ func (obj *VirtRes) Watch(processChan chan event.Event) error {
|
||||
)
|
||||
defer conn.DomainEventDeregister(callbackID)
|
||||
|
||||
// notify engine that we're running
|
||||
if err := obj.Running(processChan); err != nil {
|
||||
return err // bubble up a NACK...
|
||||
}
|
||||
|
||||
var send = false
|
||||
var exit = false
|
||||
|
||||
@@ -260,15 +255,9 @@ func (obj *VirtRes) Watch(processChan chan event.Event) error {
|
||||
case <-cuid.ConvergedTimer():
|
||||
cuid.SetConverged(true) // converged!
|
||||
continue
|
||||
|
||||
case <-Startup(startup):
|
||||
cuid.SetConverged(false)
|
||||
send = true
|
||||
obj.StateOK(false) // dirty
|
||||
}
|
||||
|
||||
if send {
|
||||
startup = true // startup finished
|
||||
send = false
|
||||
if exit, err := obj.DoSend(processChan, ""); exit || err != nil {
|
||||
return err // we exit or bubble up a NACK...
|
||||
|
||||
Reference in New Issue
Block a user