engine: resources: Simplify the Watch loop

I had some legacy unnecessary boolean for sending everywhere. Not sure
why I never re-read it, it's so easy to just copy and paste and carry
on.
This commit is contained in:
James Shubin
2025-05-25 02:12:14 -04:00
parent f73127ec23
commit b868a60f69
29 changed files with 48 additions and 244 deletions

View File

@@ -148,7 +148,6 @@ func (obj *AugeasRes) Watch(ctx context.Context) error {
obj.init.Running() // when started, notify engine that we're running
var send = false // send event?
for {
if obj.init.Debug {
obj.init.Logf("Watching: %s", obj.File) // attempting to watch...
@@ -165,17 +164,12 @@ func (obj *AugeasRes) Watch(ctx context.Context) error {
if obj.init.Debug { // don't access event.Body if event.Error isn't nil
obj.init.Logf("Event(%s): %v", event.Body.Name, event.Body.Op)
}
send = true
case <-ctx.Done(): // closed by the engine to signal shutdown
return nil
}
// do all our event sending all together to avoid duplicate msgs
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}

View File

@@ -447,8 +447,6 @@ func (obj *AwsEc2Res) Watch(ctx context.Context) error {
// longpollWatch uses the ec2 api's built in methods to watch ec2 resource
// state.
func (obj *AwsEc2Res) longpollWatch(ctx context.Context) error {
send := false
// We tell the engine that we're running right away. This is not correct,
// but the api doesn't have a way to signal when the waiters are ready.
obj.init.Running() // when started, notify engine that we're running
@@ -527,17 +525,13 @@ func (obj *AwsEc2Res) longpollWatch(ctx context.Context) error {
continue
default:
obj.init.Logf("State: %v", msg.state)
send = true
}
case <-ctx.Done(): // closed by the engine to signal shutdown
return nil
}
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}
@@ -547,7 +541,6 @@ func (obj *AwsEc2Res) longpollWatch(ctx context.Context) error {
// it can publish to. snsWatch creates an http server which listens for messages
// published to the topic and processes them accordingly.
func (obj *AwsEc2Res) snsWatch(ctx context.Context) error {
send := false
defer obj.wg.Wait()
// create the sns listener
// closing is handled by http.Server.Shutdown in the defer func below
@@ -622,16 +615,12 @@ func (obj *AwsEc2Res) snsWatch(ctx context.Context) error {
continue
}
obj.init.Logf("State: %v", msg.event)
send = true
case <-ctx.Done(): // closed by the engine to signal shutdown
return nil
}
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}

View File

@@ -296,7 +296,6 @@ func (obj *CronRes) Watch(ctx context.Context) error {
obj.init.Running() // when started, notify engine that we're running
var send = false // send event?
for {
select {
case event := <-dbusChan:
@@ -304,7 +303,6 @@ func (obj *CronRes) Watch(ctx context.Context) error {
if obj.init.Debug {
obj.init.Logf("%+v", event)
}
send = true
case event, ok := <-obj.recWatcher.Events():
// process unit file recwatch events
@@ -317,16 +315,12 @@ func (obj *CronRes) Watch(ctx context.Context) error {
if obj.init.Debug {
obj.init.Logf("Event(%s): %v", event.Body.Name, event.Body.Op)
}
send = true
case <-ctx.Done(): // closed by the engine to signal shutdown
return nil
}
// do all our event sending all together to avoid duplicate msgs
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}

View File

@@ -158,7 +158,6 @@ func (obj *DeployTar) Watch(ctx context.Context) error {
obj.init.Running() // when started, notify engine that we're running
var send = false // send event?
for {
select {
case event, ok := <-recWatcher.Events():
@@ -174,17 +173,12 @@ func (obj *DeployTar) Watch(ctx context.Context) error {
if obj.init.Debug { // don't access event.Body if event.Error isn't nil
obj.init.Logf("event(%s): %v", event.Body.Name, event.Body.Op)
}
send = true
case <-ctx.Done(): // closed by the engine to signal shutdown
return nil
}
// do all our event sending all together to avoid duplicate msgs
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}

View File

@@ -514,7 +514,6 @@ func (obj *DHCPServerRes) Watch(ctx context.Context) error {
startupChan := make(chan struct{})
close(startupChan) // send one initial signal
var send = false // send event?
for {
if obj.init.Debug {
obj.init.Logf("Looping...")
@@ -523,7 +522,6 @@ func (obj *DHCPServerRes) Watch(ctx context.Context) error {
select {
case <-startupChan:
startupChan = nil
send = true
case <-closeSignal: // something shut us down early
return closeError
@@ -532,11 +530,7 @@ func (obj *DHCPServerRes) Watch(ctx context.Context) error {
return nil
}
// do all our event sending all together to avoid duplicate msgs
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}

View File

@@ -222,7 +222,6 @@ func (obj *DockerContainerRes) Watch(ctx context.Context) error {
obj.init.Running()
}
var send = false // send event?
for {
select {
case event, ok := <-eventChan:
@@ -232,7 +231,6 @@ func (obj *DockerContainerRes) Watch(ctx context.Context) error {
if obj.init.Debug {
obj.init.Logf("%+v", event)
}
send = true
case err, ok := <-errChan:
if !ok {
@@ -244,11 +242,7 @@ func (obj *DockerContainerRes) Watch(ctx context.Context) error {
return nil
}
// do all our event sending all together to avoid duplicate msgs
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}

View File

@@ -169,7 +169,6 @@ func (obj *DockerImageRes) Watch(ctx context.Context) error {
obj.init.Running()
}
var send = false // send event?
for {
select {
case event, ok := <-eventChan:
@@ -179,7 +178,6 @@ func (obj *DockerImageRes) Watch(ctx context.Context) error {
if obj.init.Debug {
obj.init.Logf("%+v", event)
}
send = true
case err, ok := <-errChan:
if !ok {
@@ -191,11 +189,7 @@ func (obj *DockerImageRes) Watch(ctx context.Context) error {
return nil
}
// do all our event sending all together to avoid duplicate msgs
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}

View File

@@ -369,7 +369,6 @@ func (obj *ExecRes) Watch(ctx context.Context) error {
obj.init.Running() // when started, notify engine that we're running
var send = false // send event?
for {
select {
case data, ok := <-ioChan:
@@ -408,8 +407,8 @@ func (obj *ExecRes) Watch(ctx context.Context) error {
obj.init.Logf("watch out:")
obj.init.Logf("%s", s)
}
if data.text != "" {
send = true
if data.text == "" { // TODO: do we want to skip event?
continue
}
case event, ok := <-rwChan:
@@ -419,7 +418,6 @@ func (obj *ExecRes) Watch(ctx context.Context) error {
if err := event.Error; err != nil {
return errwrap.Wrapf(err, "unknown %s watcher error", obj)
}
send = true
case files, ok := <-filesChan:
if !ok { // channel shutdown
@@ -428,17 +426,12 @@ func (obj *ExecRes) Watch(ctx context.Context) error {
if err := files.Error; err != nil {
return errwrap.Wrapf(err, "unknown %s watcher error", obj)
}
send = true
case <-ctx.Done(): // closed by the engine to signal shutdown
return nil
}
// do all our event sending all together to avoid duplicate msgs
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}

View File

@@ -518,7 +518,6 @@ func (obj *FileRes) Watch(ctx context.Context) error {
obj.init.Running() // when started, notify engine that we're running
var send = false // send event?
for {
if obj.init.Debug {
obj.init.Logf("watching: %s", obj.getPath()) // attempting to watch...
@@ -538,7 +537,6 @@ func (obj *FileRes) Watch(ctx context.Context) error {
if obj.init.Debug { // don't access event.Body if event.Error isn't nil
obj.init.Logf("event(%s): %v", event.Body.Name, event.Body.Op)
}
send = true
case event, ok := <-inputEvents:
if !ok {
@@ -550,17 +548,12 @@ func (obj *FileRes) Watch(ctx context.Context) error {
if obj.init.Debug { // don't access event.Body if event.Error isn't nil
obj.init.Logf("input event(%s): %v", event.Body.Name, event.Body.Op)
}
send = true
case <-ctx.Done(): // closed by the engine to signal shutdown
return nil
}
// do all our event sending all together to avoid duplicate msgs
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}

View File

@@ -262,7 +262,6 @@ func (obj *FirewalldRes) Watch(ctx context.Context) error {
obj.init.Running() // when started, notify engine that we're running
var send = false // send event?
for {
select {
case event, ok := <-events: // &nftables.MonitorEvent
@@ -278,17 +277,11 @@ func (obj *FirewalldRes) Watch(ctx context.Context) error {
//obj.init.Logf("event data: %+v", event.Data)
}
send = true
case <-ctx.Done(): // closed by the engine to signal shutdown
return nil
}
// do all our event sending all together to avoid duplicate msgs
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}

View File

@@ -102,7 +102,6 @@ func (obj *GroupRes) Watch(ctx context.Context) error {
obj.init.Running() // when started, notify engine that we're running
var send = false // send event?
for {
if obj.init.Debug {
obj.init.Logf("Watching: %s", groupFile) // attempting to watch...
@@ -119,17 +118,12 @@ func (obj *GroupRes) Watch(ctx context.Context) error {
if obj.init.Debug { // don't access event.Body if event.Error isn't nil
obj.init.Logf("Event(%s): %v", event.Body.Name, event.Body.Op)
}
send = true
case <-ctx.Done(): // closed by the engine to signal shutdown
return nil
}
// do all our event sending all together to avoid duplicate msgs
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}

View File

@@ -243,7 +243,6 @@ func (obj *GzipRes) Watch(ctx context.Context) error {
obj.init.Running() // when started, notify engine that we're running
var send = false // send event?
for {
select {
case event, ok := <-recWatcher.Events():
@@ -259,7 +258,6 @@ func (obj *GzipRes) Watch(ctx context.Context) error {
if obj.init.Debug { // don't access event.Body if event.Error isn't nil
obj.init.Logf("event(%s): %v", event.Body.Name, event.Body.Op)
}
send = true
case event, ok := <-events:
if !ok { // channel shutdown
@@ -271,17 +269,12 @@ func (obj *GzipRes) Watch(ctx context.Context) error {
if obj.init.Debug { // don't access event.Body if event.Error isn't nil
obj.init.Logf("event(%s): %v", event.Body.Name, event.Body.Op)
}
send = true
case <-ctx.Done(): // closed by the engine to signal shutdown
return nil
}
// do all our event sending all together to avoid duplicate msgs
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}

View File

@@ -183,7 +183,6 @@ func (obj *HostnameRes) Watch(ctx context.Context) error {
obj.init.Running() // when started, notify engine that we're running
var send = false // send event?
for {
select {
case _, ok := <-signals:
@@ -191,7 +190,6 @@ func (obj *HostnameRes) Watch(ctx context.Context) error {
return fmt.Errorf("unexpected close")
}
//signals = nil
send = true
case event, ok := <-recWatcher.Events():
if !ok { // channel shutdown
@@ -203,17 +201,12 @@ func (obj *HostnameRes) Watch(ctx context.Context) error {
if obj.init.Debug { // don't access event.Body if event.Error isn't nil
obj.init.Logf("event(%s): %v", event.Body.Name, event.Body.Op)
}
send = true
case <-ctx.Done(): // closed by the engine to signal shutdown
return nil
}
// do all our event sending all together to avoid duplicate msgs
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}

View File

@@ -526,7 +526,6 @@ func (obj *HTTPServerRes) Watch(ctx context.Context) error {
startupChan := make(chan struct{})
close(startupChan) // send one initial signal
var send = false // send event?
for {
if obj.init.Debug {
obj.init.Logf("Looping...")
@@ -535,7 +534,6 @@ func (obj *HTTPServerRes) Watch(ctx context.Context) error {
select {
case <-startupChan:
startupChan = nil
send = true
case err, ok := <-multiplexedChan:
if !ok { // shouldn't happen
@@ -545,7 +543,6 @@ func (obj *HTTPServerRes) Watch(ctx context.Context) error {
if err != nil {
return err
}
send = true
case <-closeSignal: // something shut us down early
return closeError
@@ -554,11 +551,7 @@ func (obj *HTTPServerRes) Watch(ctx context.Context) error {
return nil
}
// do all our event sending all together to avoid duplicate msgs
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}

View File

@@ -203,7 +203,6 @@ func (obj *HTTPServerFlagRes) Watch(ctx context.Context) error {
startupChan := make(chan struct{})
close(startupChan) // send one initial signal
var send = false // send event?
for {
if obj.init.Debug {
obj.init.Logf("Looping...")
@@ -212,7 +211,6 @@ func (obj *HTTPServerFlagRes) Watch(ctx context.Context) error {
select {
case <-startupChan:
startupChan = nil
send = true
case err, ok := <-obj.eventStream:
if !ok { // shouldn't happen
@@ -222,17 +220,12 @@ func (obj *HTTPServerFlagRes) Watch(ctx context.Context) error {
if err != nil {
return err
}
send = true
case <-ctx.Done(): // closed by the engine to signal shutdown
return nil
}
// do all our event sending all together to avoid duplicate msgs
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}

View File

@@ -664,7 +664,6 @@ func (obj *HTTPServerUIRes) Watch(ctx context.Context) error {
startupChan := make(chan struct{})
close(startupChan) // send one initial signal
var send = false // send event?
for {
if obj.init.Debug {
obj.init.Logf("Looping...")
@@ -673,7 +672,6 @@ func (obj *HTTPServerUIRes) Watch(ctx context.Context) error {
select {
case <-startupChan:
startupChan = nil
send = true
//case err, ok := <-obj.eventStream:
// if !ok { // shouldn't happen
@@ -683,7 +681,6 @@ func (obj *HTTPServerUIRes) Watch(ctx context.Context) error {
// if err != nil {
// return err
// }
// send = true
case err, ok := <-multiplexedChan:
if !ok { // shouldn't happen
@@ -693,17 +690,12 @@ func (obj *HTTPServerUIRes) Watch(ctx context.Context) error {
if err != nil {
return err
}
send = true
case <-ctx.Done(): // closed by the engine to signal shutdown
return nil
}
// do all our event sending all together to avoid duplicate msgs
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
//return nil // unreachable

View File

@@ -253,7 +253,6 @@ func (obj *MountRes) Watch(ctx context.Context) error {
obj.init.Running() // when started, notify engine that we're running
var send bool
var done bool
for {
select {
@@ -272,8 +271,6 @@ func (obj *MountRes) Watch(ctx context.Context) error {
obj.init.Logf("event(%s): %v", event.Body.Name, event.Body.Op)
}
send = true
case event, ok := <-ch:
if !ok {
if done {
@@ -286,17 +283,11 @@ func (obj *MountRes) Watch(ctx context.Context) error {
obj.init.Logf("event: %+v", event)
}
send = true
case <-ctx.Done(): // closed by the engine to signal shutdown
return nil
}
// do all our event sending all together to avoid duplicate msgs
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}

View File

@@ -121,18 +121,9 @@ func (obj *MsgRes) Cleanup() error {
func (obj *MsgRes) Watch(ctx context.Context) error {
obj.init.Running() // when started, notify engine that we're running
//var send = false // send event?
for {
select {
case <-ctx.Done(): // closed by the engine to signal shutdown
return nil
}
// do all our event sending all together to avoid duplicate msgs
//if send {
// send = false
// obj.init.Event() // notify engine of an event (this can block)
//}
select {
case <-ctx.Done(): // closed by the engine to signal shutdown
return nil
}
}

View File

@@ -320,7 +320,6 @@ func (obj *NetRes) Watch(ctx context.Context) error {
obj.init.Running() // when started, notify engine that we're running
var send = false // send event?
var done bool
for {
select {
@@ -339,8 +338,6 @@ func (obj *NetRes) Watch(ctx context.Context) error {
obj.init.Logf("Event: %+v", s.msg)
}
send = true
case event, ok := <-recWatcher.Events():
if !ok {
if done {
@@ -356,17 +353,11 @@ func (obj *NetRes) Watch(ctx context.Context) error {
obj.init.Logf("Event(%s): %v", event.Body.Name, event.Body.Op)
}
send = true
case <-ctx.Done(): // closed by the engine to signal shutdown
return nil
}
// do all our event sending all together to avoid duplicate msgs
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}

View File

@@ -183,32 +183,27 @@ func (obj *NspawnRes) Watch(ctx context.Context) error {
obj.init.Running() // when started, notify engine that we're running
var send = false // send event?
for {
select {
case event := <-busChan:
// process org.freedesktop.machine1 events for this resource's name
if event.Body[0] == obj.Name() {
obj.init.Logf("Event received: %v", event.Name)
if event.Name == machineNew {
obj.init.Logf("Machine started")
} else if event.Name == machineRemoved {
obj.init.Logf("Machine stopped")
} else {
return fmt.Errorf("unknown event: %s", event.Name)
}
send = true
if event.Body[0] != obj.Name() {
continue
}
obj.init.Logf("Event received: %v", event.Name)
if event.Name == machineNew {
obj.init.Logf("Machine started")
} else if event.Name == machineRemoved {
obj.init.Logf("Machine stopped")
} else {
return fmt.Errorf("unknown event: %s", event.Name)
}
case <-ctx.Done(): // closed by the engine to signal shutdown
return nil
}
// do all our event sending all together to avoid duplicate msgs
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}

View File

@@ -222,7 +222,6 @@ func (obj *PasswordRes) Watch(ctx context.Context) error {
obj.init.Running() // when started, notify engine that we're running
var send = false // send event?
for {
select {
// NOTE: this part is very similar to the file resource code
@@ -233,17 +232,12 @@ func (obj *PasswordRes) Watch(ctx context.Context) error {
if err := event.Error; err != nil {
return errwrap.Wrapf(err, "unknown %s watcher error", obj)
}
send = true
case <-ctx.Done(): // closed by the engine to signal shutdown
return nil
}
// do all our event sending all together to avoid duplicate msgs
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}

View File

@@ -150,7 +150,6 @@ func (obj *PkgRes) Watch(ctx context.Context) error {
obj.init.Running() // when started, notify engine that we're running
var send = false // send event?
for {
if obj.init.Debug {
obj.init.Logf("%s: Watching...", obj.fmtNames(obj.getNames()))
@@ -169,17 +168,11 @@ func (obj *PkgRes) Watch(ctx context.Context) error {
<-ch // discard
}
send = true
case <-ctx.Done(): // closed by the engine to signal shutdown
return nil
}
// do all our event sending all together to avoid duplicate msgs
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}

View File

@@ -217,7 +217,6 @@ func (obj *SysctlRes) Watch(ctx context.Context) error {
obj.init.Running() // when started, notify engine that we're running
var send = false // send event?
for {
select {
case event, ok := <-events1:
@@ -230,7 +229,6 @@ func (obj *SysctlRes) Watch(ctx context.Context) error {
if obj.init.Debug { // don't access event.Body if event.Error isn't nil
obj.init.Logf("event(%s): %v", event.Body.Name, event.Body.Op)
}
send = true
case event, ok := <-events2:
if !ok { // channel shutdown
@@ -242,17 +240,12 @@ func (obj *SysctlRes) Watch(ctx context.Context) error {
if obj.init.Debug { // don't access event.Body if event.Error isn't nil
obj.init.Logf("event(%s): %v", event.Body.Name, event.Body.Op)
}
send = true
case <-ctx.Done(): // closed by the engine to signal shutdown
return nil
}
// do all our event sending all together to avoid duplicate msgs
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}

View File

@@ -218,7 +218,6 @@ func (obj *TarRes) Watch(ctx context.Context) error {
obj.init.Running() // when started, notify engine that we're running
var send = false // send event?
for {
select {
case event, ok := <-recWatcher.Events():
@@ -234,7 +233,6 @@ func (obj *TarRes) Watch(ctx context.Context) error {
if obj.init.Debug { // don't access event.Body if event.Error isn't nil
obj.init.Logf("event(%s): %v", event.Body.Name, event.Body.Op)
}
send = true
case event, ok := <-events:
if !ok { // channel shutdown
@@ -249,17 +247,12 @@ func (obj *TarRes) Watch(ctx context.Context) error {
if obj.init.Debug { // don't access event.Body if event.Error isn't nil
obj.init.Logf("event(%s): %v", event.Body.Name, event.Body.Op)
}
send = true
case <-ctx.Done(): // closed by the engine to signal shutdown
return nil
}
// do all our event sending all together to avoid duplicate msgs
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}

View File

@@ -199,7 +199,6 @@ func (obj *TFTPServerRes) Watch(ctx context.Context) error {
startupChan := make(chan struct{})
close(startupChan) // send one initial signal
var send = false // send event?
for {
if obj.init.Debug {
obj.init.Logf("Looping...")
@@ -208,7 +207,6 @@ func (obj *TFTPServerRes) Watch(ctx context.Context) error {
select {
case <-startupChan:
startupChan = nil
send = true
case <-closeSignal: // something shut us down early
return closeError
@@ -217,11 +215,7 @@ func (obj *TFTPServerRes) Watch(ctx context.Context) error {
return nil
}
// do all our event sending all together to avoid duplicate msgs
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}

View File

@@ -91,21 +91,16 @@ func (obj *TimerRes) Watch(ctx context.Context) error {
obj.init.Running() // when started, notify engine that we're running
var send = false // send event?
for {
select {
case <-obj.ticker.C: // received the timer event
send = true
obj.init.Logf("received tick")
case <-ctx.Done(): // closed by the engine to signal shutdown
return nil
}
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}

View File

@@ -153,7 +153,6 @@ func (obj *UserRes) Watch(ctx context.Context) error {
obj.init.Running() // when started, notify engine that we're running
var send = false // send event?
for {
if obj.init.Debug {
obj.init.Logf("watching: %s", util.EtcPasswdFile) // attempting to watch...
@@ -170,17 +169,12 @@ func (obj *UserRes) Watch(ctx context.Context) error {
if obj.init.Debug { // don't access event.Body if event.Error isn't nil
obj.init.Logf("event(%s): %v", event.Body.Name, event.Body.Op)
}
send = true
case <-ctx.Done(): // closed by the engine to signal shutdown
return nil
}
// do all our event sending all together to avoid duplicate msgs
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}

View File

@@ -437,7 +437,6 @@ func (obj *VirtBuilderRes) Watch(ctx context.Context) error {
obj.init.Running() // when started, notify engine that we're running
var send = false // send event?
for {
select {
case event, ok := <-recWatcher.Events():
@@ -450,17 +449,12 @@ func (obj *VirtBuilderRes) Watch(ctx context.Context) error {
if obj.init.Debug { // don't access event.Body if event.Error isn't nil
obj.init.Logf("event(%s): %v", event.Body.Name, event.Body.Op)
}
send = true
case <-ctx.Done(): // closed by the engine to signal shutdown
return nil
}
// do all our event sending all together to avoid duplicate msgs
if send {
send = false
obj.init.Event() // notify engine of an event (this can block)
}
obj.init.Event() // notify engine of an event (this can block)
}
}