feat: monitor 实现 Plugin 接口,优化关闭流程

- monitor 包导入 taskq,实现 Plugin 接口
- monitor 作为插件注册到 taskq.Configure()
- 修复优雅关闭顺序:先关闭 SSE 连接,再关闭 HTTP 服务器,最后停止 taskq
- 移除 main.go 中手动调用 cancel() 导致的阻塞问题
This commit is contained in:
2025-12-10 01:00:42 +08:00
parent 326f2a371c
commit 37b262eefb
2 changed files with 35 additions and 18 deletions

View File

@@ -13,6 +13,7 @@ import (
"sync"
"time"
"code.tczkiot.com/wlw/taskq"
"code.tczkiot.com/wlw/taskq/x/inspector"
)
@@ -96,6 +97,26 @@ func (m *Monitor) Close() error {
return nil
}
// Name 返回插件名称
func (m *Monitor) Name() string {
return "monitor"
}
// Init 初始化插件(实现 Plugin 接口)
func (m *Monitor) Init(ctx *taskq.Context) error {
return nil
}
// Start 启动插件(实现 Plugin 接口)
func (m *Monitor) Start(ctx *taskq.Context) error {
return nil
}
// Stop 停止插件(实现 Plugin 接口)
func (m *Monitor) Stop() error {
return m.Close()
}
// setupRoutes 设置路由
func (m *Monitor) setupRoutes() {
// API 路由