Skip to content

Commit

Permalink
add indication of file added to watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
umputun committed Dec 10, 2023
1 parent c739a8f commit a1101fa
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions app/bot/spam.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,17 @@ func (s *SpamFilter) watch(ctx context.Context) error {
}()

errs := new(multierror.Error)
errs = multierror.Append(errs, watcher.Add(s.params.ExcludedTokensFile))
errs = multierror.Append(errs, watcher.Add(s.params.SpamSamplesFile))
errs = multierror.Append(errs, watcher.Add(s.params.HamSamplesFile))
errs = multierror.Append(errs, watcher.Add(s.params.StopWordsFile))
addToWatcher := func(file string) error {
if _, err := os.Stat(file); err != nil {
return fmt.Errorf("failed to stat file %q: %w", file, err)
}
log.Printf("[DEBUG] add file %q to watcher", file)
return watcher.Add(file)
}
errs = multierror.Append(errs, addToWatcher(s.params.ExcludedTokensFile))
errs = multierror.Append(errs, addToWatcher(s.params.SpamSamplesFile))
errs = multierror.Append(errs, addToWatcher(s.params.HamSamplesFile))
errs = multierror.Append(errs, addToWatcher(s.params.StopWordsFile))
if err := errs.ErrorOrNil(); err != nil {
return fmt.Errorf("failed to add some files to watcher: %w", err)
}
Expand Down

0 comments on commit a1101fa

Please sign in to comment.