Documentation
¶
Index ¶
- func LoggingMiddleware(opts ...LoggerOption) func(next asynq.Handler) asynq.Handler
- func NewTask[P any](typeName string, payload P, opts ...asynq.Option) (*asynq.Task, error)
- func NewZapLogger(l *zap.Logger) asynq.Logger
- func RegisterTaskHandler[T any](mux *asynq.ServeMux, typeName string, handler TaskHandler[T])
- func WithDeadline(t time.Time) asynq.Option
- func WithQueue(name string) asynq.Option
- func WithRetry(maxRetry int) asynq.Option
- func WithTimeout(timeout time.Duration) asynq.Option
- func WithUniqueID(id string) asynq.Option
- type Client
- func (c *Client) Enqueue(task *asynq.Task, opts ...asynq.Option) (*asynq.TaskInfo, error)
- func (c *Client) EnqueueAt(t time.Time, typeName string, payload any, opts ...asynq.Option) (*asynq.Task, *asynq.TaskInfo, error)
- func (c *Client) EnqueueIn(delay time.Duration, typeName string, payload any, opts ...asynq.Option) (*asynq.Task, *asynq.TaskInfo, error)
- func (c *Client) EnqueueNow(typeName string, payload any, opts ...asynq.Option) (*asynq.Task, *asynq.TaskInfo, error)
- type LoggerOption
- type RedisConfig
- type RedisMode
- type Scheduler
- func (s *Scheduler) Register(cronSpec string, task *asynq.Task, opts ...asynq.Option) (entryID string, err error)
- func (s *Scheduler) RegisterTask(cronSpec string, typeName string, payload any, opts ...asynq.Option) (entryID string, err error)
- func (s *Scheduler) Run()
- func (s *Scheduler) Shutdown()
- func (s *Scheduler) Unregister(entryID string) error
- type SchedulerOption
- type Server
- func (s *Server) Mux() *asynq.ServeMux
- func (s *Server) Register(typeName string, handler asynq.Handler)
- func (s *Server) RegisterFunc(typeName string, handlerFunc asynq.HandlerFunc)
- func (s *Server) Run()
- func (s *Server) Shutdown()
- func (s *Server) Use(middlewares ...asynq.MiddlewareFunc)
- func (s *Server) WaitShutdown()
- type ServerConfig
- type TaskHandleFunc
- type TaskHandler
- type ZapLogger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoggingMiddleware ¶
func LoggingMiddleware(opts ...LoggerOption) func(next asynq.Handler) asynq.Handler
LoggingMiddleware logs information about each processed task.
func NewTask ¶
NewTask creates a new asynq.Task with a typed payload. It automatically marshals the payload into JSON.
func RegisterTaskHandler ¶
func RegisterTaskHandler[T any](mux *asynq.ServeMux, typeName string, handler TaskHandler[T])
RegisterTaskHandler registers a generic, type-safe task handler with the server's mux. It automatically unmarshals the JSON payload into the specified type.
func WithDeadline ¶
WithDeadline specifies the deadline for the task.
func WithTimeout ¶
WithTimeout specifies the timeout duration for the task.
func WithUniqueID ¶
WithUniqueID specifies that the task should be unique for a given period. If another task with the same unique ID is enqueued within the retention period, it will be rejected.
Types ¶
type Client ¶
Client is a wrapper around asynq.Client providing more convenient APIs.
func (*Client) EnqueueAt ¶
func (c *Client) EnqueueAt(t time.Time, typeName string, payload any, opts ...asynq.Option) (*asynq.Task, *asynq.TaskInfo, error)
EnqueueAt enqueues a task to be processed at a specific time.
type LoggerOption ¶
type LoggerOption func(*loggerOptions)
LoggerOption set options.
func WithLogger ¶
func WithLogger(l *zap.Logger) LoggerOption
WithLogger sets the logger to use for logging.
func WithMaxLength ¶
func WithMaxLength(l int) LoggerOption
WithMaxLength sets the maximum length of the payload to log.
type RedisConfig ¶
type RedisConfig struct { Mode RedisMode `yaml:"mode"` // For Single Mode Addr string `yaml:"addr"` // For Sentinel Mode SentinelAddrs []string `yaml:"sentinelAddrs"` MasterName string `yaml:"masterName"` // For Cluster Mode ClusterAddrs []string `yaml:"clusterAddrs"` // Common options Username string `yaml:"username"` Password string `yaml:"password"` DB int `yaml:"db"` }
RedisConfig holds all configurations for connecting to Redis.
func (*RedisConfig) GetAsynqRedisConnOpt ¶
func (c *RedisConfig) GetAsynqRedisConnOpt() asynq.RedisConnOpt
GetAsynqRedisConnOpt converts RedisConfig to asynq's RedisConnOpt interface. This is the core of the high-availability switching logic.
type RedisMode ¶
type RedisMode string
RedisMode defines the Redis connection mode.
const ( // RedisModeSingle uses a single Redis instance. RedisModeSingle RedisMode = "single" // RedisModeSentinel uses Redis Sentinel for high availability. RedisModeSentinel RedisMode = "sentinel" // RedisModeCluster uses a Redis Cluster for horizontal scaling. RedisModeCluster RedisMode = "cluster" )
type Scheduler ¶
Scheduler is a wrapper around asynq.Scheduler.
func NewScheduler ¶
func NewScheduler(cfg RedisConfig, opts ...SchedulerOption) *Scheduler
NewScheduler creates a new periodic task scheduler.
func (*Scheduler) Register ¶
func (s *Scheduler) Register(cronSpec string, task *asynq.Task, opts ...asynq.Option) (entryID string, err error)
Register adds a new periodic task.
func (*Scheduler) RegisterTask ¶
func (s *Scheduler) RegisterTask(cronSpec string, typeName string, payload any, opts ...asynq.Option) (entryID string, err error)
RegisterTask adds a new periodic task with a given type name.
func (*Scheduler) Run ¶
func (s *Scheduler) Run()
Run runs the asynq Scheduler in a separate goroutine
func (*Scheduler) Unregister ¶
Unregister removes a periodic task.
type SchedulerOption ¶
type SchedulerOption func(*schedulerOptions)
SchedulerOption set options.
func WithSchedulerLogLevel ¶
func WithSchedulerLogLevel(level asynq.LogLevel) SchedulerOption
WithSchedulerLogLevel sets the log level for the scheduler.
func WithSchedulerLogger ¶
func WithSchedulerLogger(l *zap.Logger) SchedulerOption
WithSchedulerLogger sets the logger for the scheduler.
func WithSchedulerOptions ¶
func WithSchedulerOptions(opts *asynq.SchedulerOpts) SchedulerOption
WithSchedulerOptions sets the options for the scheduler.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a wrapper around asynq.Server providing integrated features.
func NewServer ¶
func NewServer(redisCfg RedisConfig, serverCfg ServerConfig) *Server
NewServer creates a new consumer server.
func (*Server) RegisterFunc ¶
func (s *Server) RegisterFunc(typeName string, handlerFunc asynq.HandlerFunc)
RegisterFunc a task handler function
func (*Server) Use ¶
func (s *Server) Use(middlewares ...asynq.MiddlewareFunc)
Use adds middleware to the server's handler chain.
func (*Server) WaitShutdown ¶
func (s *Server) WaitShutdown()
WaitShutdown for interrupt signals for graceful shutdown the server.
type ServerConfig ¶
ServerConfig holds configurations for the asynq server.
func DefaultServerConfig ¶
func DefaultServerConfig(l ...*zap.Logger) ServerConfig
DefaultServerConfig returns a default server configuration.
type TaskHandleFunc ¶
TaskHandleFunc is a function adapter for TaskHandler.
type TaskHandler ¶
TaskHandler is a generic interface for handling a task with a specific payload type.
func HandleFunc ¶
func HandleFunc[T any](f func(ctx context.Context, payloadType T) error) TaskHandler[T]
HandleFunc creates a TaskHandler from a function.