Documentation
¶
Overview ¶
Package tasks provides Asynq background task helpers.
Index ¶
- Constants
- type Client
- func (c *Client) Close() error
- func (c *Client) Enqueue(taskType string, payload interface{}, opts ...asynq.Option) (*asynq.TaskInfo, error)
- func (c *Client) EnqueueAt(taskType string, payload interface{}, processAt time.Time, ...) (*asynq.TaskInfo, error)
- func (c *Client) EnqueueIn(taskType string, payload interface{}, delay time.Duration, ...) (*asynq.TaskInfo, error)
- type EmailNotificationPayload
- type Server
- type ServerConfig
- type SyncDataPayload
- type TaskHandler
Constants ¶
const ( TaskTypeEmailNotification = "email:notification" TaskTypeSyncData = "sync:data" TaskTypeCleanup = "maintenance:cleanup" )
Common task type constants.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps an Asynq client for enqueuing tasks.
func (*Client) Enqueue ¶
func (c *Client) Enqueue(taskType string, payload interface{}, opts ...asynq.Option) (*asynq.TaskInfo, error)
Enqueue enqueues a task with the given type and payload.
type EmailNotificationPayload ¶
type EmailNotificationPayload struct {
To string `json:"to"`
Subject string `json:"subject"`
Body string `json:"body"`
}
EmailNotificationPayload is the payload for email notification tasks.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server wraps an Asynq server for processing tasks.
func (*Server) HandleFunc ¶
HandleFunc registers a handler function for the given task type.
type ServerConfig ¶
type ServerConfig struct {
RedisAddr string
RedisPassword string
RedisDB int
Concurrency int
Queues map[string]int // Queue name -> priority
}
ServerConfig holds configuration for the task server.
func DefaultServerConfig ¶
func DefaultServerConfig(redisAddr, redisPassword string, redisDB int) *ServerConfig
DefaultServerConfig returns a default server configuration.
type SyncDataPayload ¶
type SyncDataPayload struct {
Source string `json:"source"`
Destination string `json:"destination"`
}
SyncDataPayload is the payload for data sync tasks.
type TaskHandler ¶
type TaskHandler[T any] struct { // contains filtered or unexported fields }
TaskHandler is an interface for task handlers with automatic JSON unmarshaling.
func NewTaskHandler ¶
func NewTaskHandler[T any](handler func(context.Context, T) error) *TaskHandler[T]
NewTaskHandler creates a new typed task handler.
func (*TaskHandler[T]) ProcessTask ¶
ProcessTask implements asynq.Handler.