This commit is contained in:
2026-08-16 20:58:57 +08:00
parent a85477be80
commit a9e1f9e6f8
42 changed files with 1569 additions and 156 deletions
+8 -8
View File
@@ -1,7 +1,6 @@
package data
import (
"log"
"path/filepath"
"sync"
"time"
@@ -13,22 +12,23 @@ import (
// /system/reloadSystem remains responsible
// for rebuilding database, Redis, storage, and scheduled tasks.
func (d *Data) watchConfig() func() {
logger := d.logger()
configPath := d.runtime.ConfigPath()
if configPath == "" {
return func() {}
}
absolute, err := filepath.Abs(configPath)
if err != nil {
log.Printf("resolve config watch path: %v", err)
logger.Error("resolve config watch path", "mod", "system", "error", err)
return func() {}
}
watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Printf("create config watcher: %v", err)
logger.Error("create config watcher", "mod", "system", "error", err)
return func() {}
}
if err = watcher.Add(filepath.Dir(absolute)); err != nil {
log.Printf("watch config directory: %v", err)
logger.Error("watch config directory", "mod", "system", "error", err)
_ = watcher.Close()
return func() {}
}
@@ -48,20 +48,20 @@ func (d *Data) watchConfig() func() {
timer = time.AfterFunc(100*time.Millisecond, func() {
next, loadErr := readBootstrap(absolute)
if loadErr != nil {
log.Printf("reload changed config: %v", loadErr)
logger.Error("reload changed config", "mod", "system", "error", loadErr)
return
}
if next.Data == nil || next.Admin == nil {
log.Printf("reload changed config: data and admin configuration are required")
logger.Error("reload changed config: data and admin configuration are required", "mod", "system")
return
}
next.Admin.ConfigPath = absolute
d.runtime.Replace(next.Data, next.Admin)
log.Printf("config file changed: %s", absolute)
logger.Info("config file changed", "mod", "system", "path", absolute)
})
case watchErr, ok := <-watcher.Errors:
if ok {
log.Printf("config watcher error: %v", watchErr)
logger.Error("config watcher error", "mod", "system", "error", watchErr)
}
case <-done:
if timer != nil {