feat(controller): hot-reload the notification pipes
Email, ntfy and webhook kept their settings in a plain struct field copied at construction, so editing controllerMethod in config.json wrote the file and replaced the in-memory configuration while the running channels stayed on their boot values. Add Reload to the Controller interface and implement it for the three notification pipes; Manager.ReloadAll fans an update out to every registered controller and is wired into the reload hook from main. Reload runs on the goroutine serving the settings update while the send methods run on the status-change and incoming-webhook goroutines, so storing the new settings in a plain field would be a data race. Each pipe publishes its settings — and the HTTP client derived from them — through atomic pointers, and every send takes one snapshot so a reload landing mid-send cannot split it across two configurations. Only a change to networkUseProxy rebuilds the client; everything else is read from the settings at send time, so a reload that changes nothing relevant leaves the client alone. Email needed one more fix: gomail exposes its dial hook as a package-level variable with no unset, and the constructor only installed the proxy dialer when the flag was set, so turning networkUseProxy off left SMTP tunnelled through a proxy. applyEmailProxy now restores net.DialTimeout, which is gomail's own default. QQ (Napcat) and Telegram implement Reload because the interface requires it, but neither can apply a change in place: the NapCat client is stopped through a sync.Once and the Telegram polling context is created with the controller, so both need to be rebuilt and swapped into the manager. Rather than no-op silently and let an edit look applied, they log a warning while their settings diverge. That rebuild is the next step.
This commit is contained in:
@@ -58,12 +58,17 @@ func main() {
|
||||
postLog.SetDebugMode(cfg.System.DebugMode)
|
||||
postLog.InitLogBroadcaster()
|
||||
|
||||
// The logger's debug flag is a process-wide setting rather than something
|
||||
// read at every log call, so a settings update has to push the new value
|
||||
// into it. This is the first link in the reload hook chain; the controllers
|
||||
// join it as they gain reload support.
|
||||
// A settings update replaces the configuration in memory; these hooks push
|
||||
// the new values into the state that was derived from the old one. The
|
||||
// logger's debug flag is process-wide rather than read at every log call,
|
||||
// and each controller holds its own copy of its channel settings plus the
|
||||
// clients built from them.
|
||||
config.OnReload(func(updated *config.Config) {
|
||||
postLog.SetDebugMode(updated.System.DebugMode)
|
||||
|
||||
if mgr := controller.GetManager(); mgr != nil {
|
||||
mgr.ReloadAll()
|
||||
}
|
||||
})
|
||||
|
||||
dbPath := cfg.DBPath
|
||||
|
||||
Reference in New Issue
Block a user