Skip to content

Commit

Permalink
Add fsnotify error monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
thom-at-redhat committed Oct 24, 2024
1 parent e43291d commit da706cc
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions pkg/workceptor/workunitbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
type WatcherWrapper interface {
Add(name string) error
Close() error
ErrorChannel() chan error
EventChannel() chan fsnotify.Event
}

Expand All @@ -52,6 +53,10 @@ func (rw *RealWatcher) Close() error {
return rw.watcher.Close()
}

func (rw *RealWatcher) ErrorChannel() chan error {
return rw.watcher.Errors
}

func (rw *RealWatcher) EventChannel() chan fsnotify.Event {
return rw.watcher.Events
}
Expand Down Expand Up @@ -126,6 +131,7 @@ func (bwu *BaseWorkUnit) Init(w *Workceptor, unitID string, workType string, fs
if err == nil {
bwu.watcher = &RealWatcher{watcher: watcher}
} else {
bwu.w.nc.GetLogger.Info("fsnotify.NewWatcher returned %s", err)

Check failure on line 134 in pkg/workceptor/workunitbase.go

View workflow job for this annotation

GitHub Actions / go test coverage

bwu.w.nc.GetLogger.Info undefined (type func() *logger.ReceptorLogger has no field or method Info)

Check failure on line 134 in pkg/workceptor/workunitbase.go

View workflow job for this annotation

GitHub Actions / go test coverage

bwu.w.nc.GetLogger.Info undefined (type func() *logger.ReceptorLogger has no field or method Info)

Check failure on line 134 in pkg/workceptor/workunitbase.go

View workflow job for this annotation

GitHub Actions / lint-receptor

bwu.w.nc.GetLogger.Info undefined (type func() *logger.ReceptorLogger has no field or method Info)

Check failure on line 134 in pkg/workceptor/workunitbase.go

View workflow job for this annotation

GitHub Actions / lint-receptor

bwu.w.nc.GetLogger.Info undefined (type func() *logger.ReceptorLogger has no field or method Info)

Check failure on line 134 in pkg/workceptor/workunitbase.go

View workflow job for this annotation

GitHub Actions / lint-receptor

bwu.w.nc.GetLogger.Info undefined (type func() *logger.ReceptorLogger has no field or method Info)

Check failure on line 134 in pkg/workceptor/workunitbase.go

View workflow job for this annotation

GitHub Actions / lint-receptor

bwu.w.nc.GetLogger.Info undefined (type func() *logger.ReceptorLogger has no field or method Info)

Check failure on line 134 in pkg/workceptor/workunitbase.go

View workflow job for this annotation

GitHub Actions / lint-receptor

bwu.w.nc.GetLogger.Info undefined (type func() *logger.ReceptorLogger has no field or method Info)

Check failure on line 134 in pkg/workceptor/workunitbase.go

View workflow job for this annotation

GitHub Actions / receptor (Go 1.20)

bwu.w.nc.GetLogger.Info undefined (type func() *logger.ReceptorLogger has no field or method Info)

Check failure on line 134 in pkg/workceptor/workunitbase.go

View workflow job for this annotation

GitHub Actions / receptor (Go 1.21)

bwu.w.nc.GetLogger.Info undefined (type func() *logger.ReceptorLogger has no field or method Info)
bwu.watcher = nil
}
}
Expand Down Expand Up @@ -392,6 +398,9 @@ func (bwu *BaseWorkUnit) MonitorLocalStatus() {
var watcherEvents chan fsnotify.Event
watcherEvents = make(chan fsnotify.Event)

var watcherErrors chan error
watcherErrors = make(chan error)

if bwu.watcher != nil {
err := bwu.watcher.Add(statusFile)
if err == nil {
Expand All @@ -402,6 +411,7 @@ func (bwu *BaseWorkUnit) MonitorLocalStatus() {
}
}()
watcherEvents = bwu.watcher.EventChannel()
watcherErrors = bwu.watcher.ErrorChannel()
} else {
werr := bwu.watcher.Close()
if werr != nil {
Expand All @@ -412,6 +422,7 @@ func (bwu *BaseWorkUnit) MonitorLocalStatus() {
}
fi, err := bwu.fs.Stat(statusFile)
if err != nil {
bwu.w.nc.GetLogger().Error("Error retrieving stat for %s: %s", statusFile, err)
fi = nil
}

Expand All @@ -436,11 +447,11 @@ loop:
bwu.w.nc.GetLogger().Error("Error reading %s: %s", statusFile, err)
}
}
case err, ok := <-watcher.Errors:
if !ok {
return
}
bwu.w.nc.GetLogger()Error("fsnotify Error reading %s: %s", statusFile, err)
case err, ok := <-watcherErrors:
if !ok {
return
}
bwu.w.nc.GetLogger().Error("fsnotify Error reading %s: %s", statusFile, err)
}
complete := IsComplete(bwu.Status().State)
if complete {
Expand Down

0 comments on commit da706cc

Please sign in to comment.