resources, pgraph: Refactor Worker and simplify API
I'm still working on reducing the size of the monster patches that I land, but I'm exercising the priviledge as the initial author. In any case, this refactors worker into two, and cleans up the passing around of the processChan. This puts common code into Init and Close.
This commit is contained in:
@@ -29,8 +29,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/purpleidea/mgmt/event"
|
||||
|
||||
multierr "github.com/hashicorp/go-multierror"
|
||||
"github.com/libvirt/libvirt-go"
|
||||
libvirtxml "github.com/libvirt/libvirt-go-xml"
|
||||
@@ -250,7 +248,7 @@ func (obj *VirtRes) connect() (conn *libvirt.Connect, err error) {
|
||||
}
|
||||
|
||||
// Watch is the primary listener for this resource and it outputs events.
|
||||
func (obj *VirtRes) Watch(processChan chan *event.Event) error {
|
||||
func (obj *VirtRes) Watch() error {
|
||||
domChan := make(chan libvirt.DomainEventType) // TODO: do we need to buffer this?
|
||||
gaChan := make(chan *libvirt.DomainEventAgentLifecycle)
|
||||
errorChan := make(chan error)
|
||||
@@ -308,7 +306,7 @@ func (obj *VirtRes) Watch(processChan chan *event.Event) error {
|
||||
defer obj.conn.DomainEventDeregister(gaCallbackID)
|
||||
|
||||
// notify engine that we're running
|
||||
if err := obj.Running(processChan); err != nil {
|
||||
if err := obj.Running(); err != nil {
|
||||
return err // bubble up a NACK...
|
||||
}
|
||||
|
||||
@@ -400,7 +398,7 @@ func (obj *VirtRes) Watch(processChan chan *event.Event) error {
|
||||
|
||||
if send {
|
||||
send = false
|
||||
obj.Event(processChan)
|
||||
obj.Event()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user