Files
taskq/plugin.go

42 lines
985 B
Go
Raw Normal View History

package taskq
import (
"context"
"github.com/redis/go-redis/v9"
)
// Context 插件上下文,提供对 Servlet 资源的访问
type Context struct {
context.Context
servlet *Servlet
}
// Redis 返回 Redis 客户端
func (ctx *Context) Redis() redis.UniversalClient {
return ctx.servlet.redisClient
}
// Queues 返回队列优先级配置
func (ctx *Context) Queues() map[string]int {
return ctx.servlet.Queues()
}
// Plugin 定义插件接口,用于扩展 Servlet 的生命周期
type Plugin interface {
// Name 返回插件名称,用于日志和调试
Name() string
// Init 初始化插件,在 Servlet.Start 之前调用
// ctx 提供对 Servlet 资源的访问
Init(ctx *Context) error
// Start 启动插件,在 Servlet.Start 时调用
// ctx 提供对 Servlet 资源的访问,内嵌的 context.Context 会在 Stop 时取消
Start(ctx *Context) error
// Stop 停止插件,在 Servlet.Stop 时调用
// 按注册的逆序调用
Stop() error
}