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:
@@ -86,6 +86,23 @@ func (q *QQController) IsEnabled() bool {
|
||||
return q.cfg.Enabled
|
||||
}
|
||||
|
||||
// Reload is not implemented yet for this channel.
|
||||
//
|
||||
// Everything this controller uses — the NapCat address, port and token — is
|
||||
// captured in the client it connected with, and that client's WebSocket
|
||||
// listener is stopped through a sync.Once and cannot be re-pointed. Applying a
|
||||
// change therefore means stopping the client and building a replacement
|
||||
// controller, which lands together with the Telegram one. Until then the
|
||||
// divergence is reported rather than ignored, so an edit that needs a restart
|
||||
// does not look like it took effect.
|
||||
func (q *QQController) Reload() {
|
||||
global := config.Current()
|
||||
if global == nil || q.cfg == global.ControllerMethod.QQ {
|
||||
return
|
||||
}
|
||||
postLog.Warning("QQ (Napcat) settings changed but hot reload is not implemented for this channel yet; restart to apply them")
|
||||
}
|
||||
|
||||
// IsMarkdown returns whether the channel renders Markdown, per its markdown
|
||||
// setting in config.json.
|
||||
func (q *QQController) IsMarkdown() bool {
|
||||
|
||||
Reference in New Issue
Block a user