Documentation
¶
Index ¶
- type AsyncClient
- func (c *AsyncClient) Close() error
- func (c *AsyncClient) Enqueue(taskType string, payload interface{}, opts ...TaskOption) (*asynq.TaskInfo, error)
- func (c *AsyncClient) GetQueueInfo(queue string) (*asynq.QueueInfo, error)
- func (c *AsyncClient) HealthCheck() error
- func (c *AsyncClient) Ping() error
- type ClientConfig
- type ClientOption
- type DefaultRetryStrategy
- type RetryStrategy
- type Service
- func (s *Service) Debug(args ...interface{})
- func (s *Service) Error(args ...interface{})
- func (s *Service) Fatal(args ...interface{})
- func (s *Service) Info(args ...interface{})
- func (s *Service) RegisterHandler(taskType string, handler TaskHandler)
- func (s *Service) Shutdown()
- func (s *Service) Start() error
- func (s *Service) Warn(args ...interface{})
- type ServiceConfig
- type TaskHandler
- type TaskOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AsyncClient ¶
type AsyncClient struct {
// contains filtered or unexported fields
}
AsyncClient Asynchronous task queue client 异步任务队列客户端
func NewClient ¶
func NewClient(cfg ClientConfig, opts ...ClientOption) *AsyncClient
NewClient Create a singleton client instance (Thread-safe) 创建单例客户端实例(线程安全)
func (*AsyncClient) Close ¶
func (c *AsyncClient) Close() error
Close Gracefully close connection 优雅关闭连接
func (*AsyncClient) Enqueue ¶
func (c *AsyncClient) Enqueue(taskType string, payload interface{}, opts ...TaskOption) (*asynq.TaskInfo, error)
Enqueue Add task to queue (Thread-safe) 添加任务到队列(线程安全)
func (*AsyncClient) GetQueueInfo ¶
func (c *AsyncClient) GetQueueInfo(queue string) (*asynq.QueueInfo, error)
GetQueueInfo Get queue information (Support dynamic inspection) 获取队列信息(支持动态检查)
func (*AsyncClient) HealthCheck ¶
func (c *AsyncClient) HealthCheck() error
HealthCheck Connection health monitor 连接健康监控
func (*AsyncClient) Ping ¶
func (c *AsyncClient) Ping() error
Ping Check Redis connection status 检查Redis连接状态
type ClientConfig ¶
type ClientConfig struct {
Addr string // Redis服务器地址 Host:Port
Password string // Redis认证密码
DB int // Redis数据库编号 0-15
PoolSize int // 连接池大小(建议为最大并发数2倍)
DialTimeout time.Duration // 连接建立超时时间
ReadTimeout time.Duration // 读取操作超时时间
WriteTimeout time.Duration // 写入操作超时时间
}
ClientConfig Redis client configuration parameters Redis客户端配置参数
type ClientOption ¶
type ClientOption func(*clientOptions)
ClientOption Client configuration options 客户端配置选项
func WithLogger ¶
func WithLogger(logger *zap.Logger) ClientOption
WithLogger Custom logger configuration 自定义日志配置
type DefaultRetryStrategy ¶
type DefaultRetryStrategy struct{}
type RetryStrategy ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func NewService(cfg *ServiceConfig) *Service
func (*Service) RegisterHandler ¶
func (s *Service) RegisterHandler(taskType string, handler TaskHandler)
以下方法保持不变
type ServiceConfig ¶
type ServiceConfig struct {
RedisAddress string
RedisPassword string
RedisDB int
Concurrency int
RetryStrategy RetryStrategy
Queues map[string]int
Logger *zap.Logger // 新增Logger字段
}
ServiceConfig contains configuration for Asynq service
type TaskOption ¶
type TaskOption func(*taskOptions)
TaskOption Functional options pattern for task configuration 任务配置的功能选项模式
func WithDeadline ¶
func WithDeadline(deadline time.Time) TaskOption
WithDeadline Set task deadline 设置任务截止时间
func WithDelay ¶
func WithDelay(delay time.Duration) TaskOption
任务选项配置函数 WithDelay Set task delay execution time 设置任务延迟执行时间
func WithMaxRetry ¶
func WithMaxRetry(maxRetry int) TaskOption
WithMaxRetry Set maximum retry attempts 设置最大重试次数
func WithTimeout ¶
func WithTimeout(timeout time.Duration) TaskOption
WithTimeout Set task processing timeout 设置任务处理超时
func WithUnique ¶
func WithUnique(ttl time.Duration) TaskOption
WithUnique Set unique task lock TTL (Prevent duplicate tasks) 设置唯一任务锁定时间(防止重复任务)