Skip to content
Snippets Groups Projects
Commit a08f277e authored by Neil-Jocelyn Schark's avatar Neil-Jocelyn Schark
Browse files

renamed

parent 3f01751c
No related branches found
No related tags found
No related merge requests found
Pipeline #272086 passed
......@@ -9,8 +9,8 @@ import (
"go.uber.org/zap"
)
// Implement the ConfigWatcher interface for yaml configuration files.
type YamlWatcher struct {
// Implement the ConfigWatcher interface for configuration files.
type FileWatcher struct {
// This channel is used to communicate with the outside
outgoingChannel chan ports.ChangeNotification
directoryPathToWatch string
......@@ -24,26 +24,27 @@ type YamlWatcher struct {
}
// NewYamlWatcher creates a new YamlWatcher instance.
func NewYamlWatcher(logger *zap.SugaredLogger) *YamlWatcher {
func NewYamlWatcher(logger *zap.SugaredLogger) *FileWatcher {
// Create buffered channel. 1024 is just an arbitrary number.
// We expect each notification event to be 32bytes, so 1024 has no meaningful impact to performance.
channel := make(chan ports.ChangeNotification, 1024)
return &YamlWatcher{logger: logger, outgoingChannel: channel}
return &FileWatcher{logger: logger, outgoingChannel: channel}
}
// ConfigureWatcher configures the watcher with a path and a channel.
func (y *YamlWatcher) ConfigureWatcher(path string) {
// ConfigureWatcher configures the watcher with a path and options.
// Options is here used for the file suffixes the watcher should look for.
func (y *FileWatcher) ConfigureWatcher(path string) {
y.directoryPathToWatch = path
}
// GetChannel returns the channel that is used to communicate with the outside.
func (y *YamlWatcher) GetChannel() chan ports.ChangeNotification {
func (y *FileWatcher) GetChannel() chan ports.ChangeNotification {
return y.outgoingChannel
}
// StartWatcher starts the watcher.
func (y *YamlWatcher) StartWatcher() error {
func (y *FileWatcher) StartWatcher() error {
y.logger.Infof("starting watcher for path %s", y.directoryPathToWatch)
ctx, cancel := context.WithCancel(context.Background())
......@@ -55,7 +56,7 @@ func (y *YamlWatcher) StartWatcher() error {
}
// StopWatcher stops the watcher. Uses the generic Close() interface.
func (y *YamlWatcher) StopWatcher() error {
func (y *FileWatcher) StopWatcher() error {
y.logger.Infof("stopping watcher for path %s", y.directoryPathToWatch)
err := y.Close()
......@@ -67,14 +68,14 @@ func (y *YamlWatcher) StopWatcher() error {
}
// Close stops the watcher.
func (y *YamlWatcher) Close() error {
func (y *FileWatcher) Close() error {
close(y.outgoingChannel)
y.watcherCancel()
return nil
}
func (y *YamlWatcher) watching(ctx context.Context) {
func (y *FileWatcher) watching(ctx context.Context) {
watcher, err := fsnotify.NewWatcher()
if err != nil {
y.logger.Errorw("failed to create watcher", "error", err)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment