Documentation
¶
Overview ¶
Package worker provides functionality for processing tasks in a worker pool
Index ¶
Constants ¶
const TaskIDHeaderKey = "task_id"
TaskIDHeaderKey is the key for the task ID in the headers
Variables ¶
This section is empty.
Functions ¶
func SerializeTaskData ¶
func SerializeTaskData[T any]( encoder encoding.EncoderFunc, task T, ) ([]byte, error)
SerializeTaskData serializes task data using the provided encoder
Types ¶
type Consumer ¶
type Consumer interface {
Consume(handler TaskHandlerFunc) error
}
Consumer defines an interface for task consumers that provide a channel of tasks
type Error ¶
Error is an error that occurs during task processing and must must be handled in one of the predefined ways. We do not allow returnning generic error interface, as it leaves too much flexibility to the caller. Middleware authors may introduce their own types, that must however be handled in the middleware itself.
type MessageFormat ¶
type MessageFormat interface {
// Serialize converts a task into binary format
Serialize(t *Task) ([]byte, error)
// Deserialize converts binary data into a task
Deserialize(data []byte) (*Task, error)
}
MessageFormat defines the interface for serializing and deserializing tasks Can be optionally used by Consumer and Publisher implementations, it's not a requirement though
func NewBinaryMessageFormat ¶
func NewBinaryMessageFormat() MessageFormat
NewBinaryMessageFormat creates a new binary message format implementation
type Middleware ¶
Middleware defines an interface for task processing middleware
type Task ¶
Task represents a unit of work with type, headers and data
type TaskHandler ¶
TaskHandler is an interface for processing tasks
func NewGenericTaskHandler ¶
func NewGenericTaskHandler[T any]( theType string, decoder encoding.DecoderFunc, processor func(headers map[string]string, data *T) *Error, ) TaskHandler
NewGenericTaskHandler creates a new generic task handler for a specific task type
type TaskHandlerFunc ¶
TaskHandlerFunc is a function that handles a task
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker represents a task processing worker that can handle multiple task types
func NewWorker ¶
func NewWorker(handlers []TaskHandler, middleware []Middleware) *Worker
NewWorker creates a new worker instance with the specified handlers and middleware