feat: enable polling configs for systems with broken fsnotify (docker volumes on windows) (#2081)

* feat: enable polling configs for systems with broken fsnotify (docker volumes on windows)

Signed-off-by: Chris Jowett <421501+cryptk@users.noreply.github.com>

* fix: update logging to make it clear that the config file is being polled

Signed-off-by: Chris Jowett <421501+cryptk@users.noreply.github.com>

---------

Signed-off-by: Chris Jowett <421501+cryptk@users.noreply.github.com>
This commit is contained in:
cryptk 2024-04-19 19:31:15 -05:00 committed by GitHub
parent 1e37101930
commit b9e7708643
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 32 additions and 7 deletions

View file

@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path"
"time"
"github.com/fsnotify/fsnotify"
"github.com/go-skynet/LocalAI/core/config"
@ -66,6 +67,20 @@ func (c *configFileHandler) Watch() error {
log.Fatal().Err(err).Str("configdir", c.configDir).Msg("wnable to create a watcher for configuration directory")
}
if c.appConfig.DynamicConfigsDirPollInterval > 0 {
log.Debug().Msg("Poll interval set, falling back to polling for configuration changes")
ticker := time.NewTicker(c.appConfig.DynamicConfigsDirPollInterval)
go func() {
for {
<-ticker.C
for file, handler := range c.handlers {
log.Debug().Str("file", file).Msg("polling config file")
c.callHandler(file, handler)
}
}
}()
}
// Start listening for events.
go func() {
for {