From b868a60f69a8bef6e0cd4b0264ac8f4bcccce44f Mon Sep 17 00:00:00 2001 From: James Shubin Date: Sun, 25 May 2025 02:12:14 -0400 Subject: [PATCH] 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. --- docs/resource-guide.md | 12 ++++-------- engine/resources/augeas.go | 8 +------- engine/resources/aws_ec2.go | 15 ++------------- engine/resources/cron.go | 10 ++-------- engine/resources/deploy_tar.go | 8 +------- engine/resources/dhcp.go | 8 +------- engine/resources/docker_container.go | 8 +------- engine/resources/docker_image.go | 8 +------- engine/resources/exec.go | 13 +++---------- engine/resources/file.go | 9 +-------- engine/resources/firewalld.go | 9 +-------- engine/resources/group.go | 8 +------- engine/resources/gzip.go | 9 +-------- engine/resources/hostname.go | 9 +-------- engine/resources/http_server.go | 9 +-------- engine/resources/http_server_flag.go | 9 +-------- engine/resources/http_server_ui.go | 10 +--------- engine/resources/mount.go | 11 +---------- engine/resources/msg.go | 15 +++------------ engine/resources/net.go | 11 +---------- engine/resources/nspawn.go | 27 +++++++++++---------------- engine/resources/password.go | 8 +------- engine/resources/pkg.go | 9 +-------- engine/resources/sysctl.go | 9 +-------- engine/resources/tar.go | 9 +-------- engine/resources/tftp.go | 8 +------- engine/resources/timer.go | 7 +------ engine/resources/user.go | 8 +------- engine/resources/virt_builder.go | 8 +------- 29 files changed, 48 insertions(+), 244 deletions(-) diff --git a/docs/resource-guide.md b/docs/resource-guide.md index fec07ebf..1b0486c2 100644 --- a/docs/resource-guide.md +++ b/docs/resource-guide.md @@ -361,14 +361,14 @@ func (obj *FooRes) Watch(ctx context.Context) error { // notify engine that we're running obj.init.Running() // when started, notify engine that we're running - var send = false // send event? for { select { // the actual events! case event := <-obj.foo.Events: - if is_an_event { - send = true + if !is_an_event { + continue // skip event } + // send below... // event errors case err := <-obj.foo.Errors: @@ -378,11 +378,7 @@ func (obj *FooRes) 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() - } + obj.init.Event() // notify engine of an event (this can block) } } ``` diff --git a/engine/resources/augeas.go b/engine/resources/augeas.go index 24fa8dec..21d69ac5 100644 --- a/engine/resources/augeas.go +++ b/engine/resources/augeas.go @@ -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) } } diff --git a/engine/resources/aws_ec2.go b/engine/resources/aws_ec2.go index b7c29e55..17035f17 100644 --- a/engine/resources/aws_ec2.go +++ b/engine/resources/aws_ec2.go @@ -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) } } diff --git a/engine/resources/cron.go b/engine/resources/cron.go index 213cbfa7..9b24ef25 100644 --- a/engine/resources/cron.go +++ b/engine/resources/cron.go @@ -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) } } diff --git a/engine/resources/deploy_tar.go b/engine/resources/deploy_tar.go index 773cfa80..ee2d2f09 100644 --- a/engine/resources/deploy_tar.go +++ b/engine/resources/deploy_tar.go @@ -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) } } diff --git a/engine/resources/dhcp.go b/engine/resources/dhcp.go index 802876b0..b1c36b85 100644 --- a/engine/resources/dhcp.go +++ b/engine/resources/dhcp.go @@ -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) } } diff --git a/engine/resources/docker_container.go b/engine/resources/docker_container.go index c024350e..5505fa94 100644 --- a/engine/resources/docker_container.go +++ b/engine/resources/docker_container.go @@ -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) } } diff --git a/engine/resources/docker_image.go b/engine/resources/docker_image.go index d8edfb94..ebea84ec 100644 --- a/engine/resources/docker_image.go +++ b/engine/resources/docker_image.go @@ -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) } } diff --git a/engine/resources/exec.go b/engine/resources/exec.go index 629524ab..4ed507ae 100644 --- a/engine/resources/exec.go +++ b/engine/resources/exec.go @@ -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) } } diff --git a/engine/resources/file.go b/engine/resources/file.go index fba99fb3..d23e7cf4 100644 --- a/engine/resources/file.go +++ b/engine/resources/file.go @@ -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) } } diff --git a/engine/resources/firewalld.go b/engine/resources/firewalld.go index b6438eec..35a9d11e 100644 --- a/engine/resources/firewalld.go +++ b/engine/resources/firewalld.go @@ -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) } } diff --git a/engine/resources/group.go b/engine/resources/group.go index 2b080ab2..78e705af 100644 --- a/engine/resources/group.go +++ b/engine/resources/group.go @@ -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) } } diff --git a/engine/resources/gzip.go b/engine/resources/gzip.go index 2256e2f8..75debc96 100644 --- a/engine/resources/gzip.go +++ b/engine/resources/gzip.go @@ -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) } } diff --git a/engine/resources/hostname.go b/engine/resources/hostname.go index 61be33e1..4299c63b 100644 --- a/engine/resources/hostname.go +++ b/engine/resources/hostname.go @@ -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) } } diff --git a/engine/resources/http_server.go b/engine/resources/http_server.go index c5b67499..43ecf040 100644 --- a/engine/resources/http_server.go +++ b/engine/resources/http_server.go @@ -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) } } diff --git a/engine/resources/http_server_flag.go b/engine/resources/http_server_flag.go index 098dfc21..ee6302fe 100644 --- a/engine/resources/http_server_flag.go +++ b/engine/resources/http_server_flag.go @@ -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) } } diff --git a/engine/resources/http_server_ui.go b/engine/resources/http_server_ui.go index 39996dae..679ac7dc 100644 --- a/engine/resources/http_server_ui.go +++ b/engine/resources/http_server_ui.go @@ -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 diff --git a/engine/resources/mount.go b/engine/resources/mount.go index d47871d2..0d1cce77 100644 --- a/engine/resources/mount.go +++ b/engine/resources/mount.go @@ -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) } } diff --git a/engine/resources/msg.go b/engine/resources/msg.go index 7d2d19ec..14d91ec4 100644 --- a/engine/resources/msg.go +++ b/engine/resources/msg.go @@ -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 } } diff --git a/engine/resources/net.go b/engine/resources/net.go index a6d4282d..9edfc1a8 100644 --- a/engine/resources/net.go +++ b/engine/resources/net.go @@ -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) } } diff --git a/engine/resources/nspawn.go b/engine/resources/nspawn.go index 6ab16977..e8e9ae8f 100644 --- a/engine/resources/nspawn.go +++ b/engine/resources/nspawn.go @@ -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) } } diff --git a/engine/resources/password.go b/engine/resources/password.go index 0dd59a6c..ff046c1c 100644 --- a/engine/resources/password.go +++ b/engine/resources/password.go @@ -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) } } diff --git a/engine/resources/pkg.go b/engine/resources/pkg.go index c6d9ff3b..225560ba 100644 --- a/engine/resources/pkg.go +++ b/engine/resources/pkg.go @@ -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) } } diff --git a/engine/resources/sysctl.go b/engine/resources/sysctl.go index aaf0f88a..069802ce 100644 --- a/engine/resources/sysctl.go +++ b/engine/resources/sysctl.go @@ -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) } } diff --git a/engine/resources/tar.go b/engine/resources/tar.go index cbd306b3..83622507 100644 --- a/engine/resources/tar.go +++ b/engine/resources/tar.go @@ -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) } } diff --git a/engine/resources/tftp.go b/engine/resources/tftp.go index 756c843b..f0f5171a 100644 --- a/engine/resources/tftp.go +++ b/engine/resources/tftp.go @@ -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) } } diff --git a/engine/resources/timer.go b/engine/resources/timer.go index 6db7fd3d..d3f499e1 100644 --- a/engine/resources/timer.go +++ b/engine/resources/timer.go @@ -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) } } diff --git a/engine/resources/user.go b/engine/resources/user.go index 4bcb47e5..b68b60d1 100644 --- a/engine/resources/user.go +++ b/engine/resources/user.go @@ -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) } } diff --git a/engine/resources/virt_builder.go b/engine/resources/virt_builder.go index bcaf927e..8a6d28f9 100644 --- a/engine/resources/virt_builder.go +++ b/engine/resources/virt_builder.go @@ -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) } }