feat(sdk): add RegisterStopHandler/RunStopHandlers and wire stop cleanup into registry lifecycle

- SDK PluginSDK gains RegisterStopHandler(fn func()) + RunStopHandlers()
  (LIFO, idempotent, cleared after running); synced to third_party copy
- Registry keeps per-plugin SDK refs (sdkRefs); StopAll/ReloadOne/
  DisablePlugin run handlers before calling Stop()
- timer built-in plugin demonstrates handler-based shutdown cleanup
- z_bridge (linux/windows templates) runs handlers before plugin.Stop()
This commit is contained in:
root
2026-08-02 10:23:40 +08:00
parent 94312d714a
commit 1013aa0aa9
6 changed files with 66 additions and 9 deletions

View File

@ -42,6 +42,8 @@ func (p *Plugin) Name() string { return p.name }
func (p *Plugin) Start(s *sdk.PluginSDK) error {
s.SetAutoRestart(true)
p.maxDur = 24 * time.Hour
// 停止清理(取消倒计时)交由 stop handler内核在调用 Stop() 之前执行。
s.RegisterStopHandler(func() { close(p.stopCh) })
s.Settings().RegisterDef(sdk.ConfigDef{
Key: "max_duration", Type: "string", DisplayName: "最大定时时长",
Description: "允许设置的最大定时时长,例如 24h, 7d, 1h默认 24h",
@ -118,7 +120,6 @@ func (p *Plugin) Start(s *sdk.PluginSDK) error {
}
func (p *Plugin) Stop() error {
close(p.stopCh)
p.wg.Wait()
return nil
}