Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions internal/extproc/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ type ConfigReceiver interface {
}

type configWatcher struct {
lastMod time.Time
path string
rcv ConfigReceiver
l *slog.Logger
current string
lastMod time.Time
path string
rcv ConfigReceiver
l *slog.Logger
current string
usingDefaultCfg bool
}

// StartConfigWatcher starts a watcher for the given path and Receiver.
Expand Down Expand Up @@ -81,13 +82,18 @@ func (cw *configWatcher) loadConfig(ctx context.Context) error {
}

if cfg != nil {
if cw.usingDefaultCfg { // Do not re-reload the same thing on every tick
Comment thread
mathetake marked this conversation as resolved.
Outdated
return nil
}
cw.l.Info("config file does not exist; loading default config", slog.String("path", cw.path))
cw.lastMod = time.Now()
cw.usingDefaultCfg = true
} else {
cw.l.Info("loading a new config", slog.String("path", cw.path))
cw.usingDefaultCfg = false
if stat.ModTime().Sub(cw.lastMod) <= 0 {
return nil
}
cw.l.Info("loading a new config", slog.String("path", cw.path))
cw.lastMod = stat.ModTime()
cfg, raw, err = filterapi.UnmarshalConfigYaml(cw.path)
if err != nil {
Expand Down