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:
James Shubin
2017-02-10 09:37:12 -05:00
parent 2da21f90f4
commit fccf508dde
16 changed files with 276 additions and 274 deletions

View File

@@ -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()
}
}
}