Documentation
¶
Overview ¶
Package handlers provides the task handler registry for the scheduler.
Index ¶
- type HandlerFunc
- type MiddlewareFunc
- type Registry
- func (r *Registry) Get(taskType string) (HandlerFunc, bool)
- func (r *Registry) GetMux() *asynq.ServeMux
- func (r *Registry) Has(taskType string) bool
- func (r *Registry) ListTypes() []string
- func (r *Registry) Register(taskType string, handler HandlerFunc)
- func (r *Registry) Unregister(taskType string)
- func (r *Registry) WithMiddleware(middleware ...MiddlewareFunc)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HandlerFunc ¶
HandlerFunc is a function that handles an Asynq task.
type MiddlewareFunc ¶
type MiddlewareFunc func(HandlerFunc) HandlerFunc
MiddlewareFunc is middleware for task handlers.
func LoggingMiddleware ¶
func LoggingMiddleware(logFn func(format string, args ...any)) MiddlewareFunc
LoggingMiddleware creates a middleware that logs task execution.
func RecoveryMiddleware ¶
func RecoveryMiddleware(logFn func(format string, args ...any)) MiddlewareFunc
RecoveryMiddleware creates a middleware that recovers from panics.
func TimeoutMiddleware ¶
func TimeoutMiddleware(logFn func(format string, args ...any)) MiddlewareFunc
TimeoutMiddleware creates a middleware that enforces task timeout. Note: Asynq already handles timeouts, this is for additional logging.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages task handlers.
func NewEmptyRegistry ¶
func NewEmptyRegistry() *Registry
NewEmptyRegistry creates an empty handler registry.
func NewRegistry ¶
func NewRegistry() *Registry
NewRegistry creates a new handler registry with default handlers.
func (*Registry) Get ¶
func (r *Registry) Get(taskType string) (HandlerFunc, bool)
Get returns the handler for the given task type.
func (*Registry) Register ¶
func (r *Registry) Register(taskType string, handler HandlerFunc)
Register adds a handler for the given task type.
func (*Registry) Unregister ¶
Unregister removes a handler for the given task type.
func (*Registry) WithMiddleware ¶
func (r *Registry) WithMiddleware(middleware ...MiddlewareFunc)
WithMiddleware wraps all handlers with the given middleware.