Skip to content

Commit

Permalink
Address some observations
Browse files Browse the repository at this point in the history
Signed-off-by: Ruben Vargas <[email protected]>
  • Loading branch information
rubenvp8510 committed May 21, 2020
1 parent 33a921c commit 9cd1b4e
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions cmd/query/app/static_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,28 +130,21 @@ func (sH *StaticAssetsHandler) configListener(watcher *fsnotify.Watcher) {
for {
select {
case event := <-watcher.Events:
if event.Op&fsnotify.Remove == fsnotify.Remove {
// this might be related to a file inside the dir, so, just log a warn if this is about the file we care about
// otherwise, just ignore the event
if event.Name == sH.options.UIConfigPath {
sH.options.Logger.Warn("the UI config file has been removed, using the last known version")
}
// Ignore if the event filename is not the UI configuration or if it is a chmod event.
if filepath.Base(event.Name) != filepath.Base(sH.options.UIConfigPath) || event.Op&fsnotify.Chmod == fsnotify.Chmod {
continue
}
if event.Op&fsnotify.Write != fsnotify.Write && event.Op&fsnotify.Create != fsnotify.Create {
if event.Op&fsnotify.Remove == fsnotify.Remove {
sH.options.Logger.Warn("the UI config file has been removed, using the last known version")
continue
}
if event.Name == sH.options.UIConfigPath {
// this will catch events for all files inside the same directory, which is OK if we don't have many changes
sH.options.Logger.Info("reloading UI config", zap.String("filename", sH.options.UIConfigPath))

content, err := loadIndexBytes(sH.assetsFS.Open, sH.options)
if err != nil {
sH.options.Logger.Error("error while reloading the UI config", zap.Error(err))
}

sH.indexHTML.Store(content)
// this will catch events for all files inside the same directory, which is OK if we don't have many changes
sH.options.Logger.Info("reloading UI config", zap.String("filename", sH.options.UIConfigPath))
content, err := loadIndexBytes(sH.assetsFS.Open, sH.options)
if err != nil {
sH.options.Logger.Error("error while reloading the UI config", zap.Error(err))
}
sH.indexHTML.Store(content)
case err, ok := <-watcher.Errors:
if !ok {
return
Expand Down

0 comments on commit 9cd1b4e

Please sign in to comment.