diff --git a/pkg/workceptor/workunitbase.go b/pkg/workceptor/workunitbase.go index 36d156354..a8af7817e 100644 --- a/pkg/workceptor/workunitbase.go +++ b/pkg/workceptor/workunitbase.go @@ -37,6 +37,7 @@ const ( type WatcherWrapper interface { Add(name string) error Close() error + ErrorChannel() chan error EventChannel() chan fsnotify.Event } @@ -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 } @@ -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) bwu.watcher = nil } } @@ -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 { @@ -402,6 +411,7 @@ func (bwu *BaseWorkUnit) MonitorLocalStatus() { } }() watcherEvents = bwu.watcher.EventChannel() + watcherErrors = bwu.watcher.ErrorChannel() } else { werr := bwu.watcher.Close() if werr != nil { @@ -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 } @@ -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 {