Documentation
¶
Overview ¶
Package workqueue provides a task queue with single-consumer semantics. Each task is processed by exactly one worker.
Index ¶
Constants ¶
const (
// PluginName identifies this plugin.
PluginName = "workqueue"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Shutdownable ¶
Shutdownable is implemented by WorkQueue implementations that need graceful shutdown.
type Task ¶
type Task struct {
ID string // Unique identifier
Queue string // Queue name
Data any // Payload
Attempt int // Processing attempt (1-based)
// contains filtered or unexported fields
}
Task wraps task data with metadata.
func NewTaskWithCallbacks ¶
NewTaskWithCallbacks creates a task with custom ack/nack callbacks.
type WorkQueue ¶
type WorkQueue interface {
// Subscribe registers a handler that competes with other handlers.
// Only one handler will process each task.
Subscribe(queue string, handler Handler)
// Enqueue adds a task to the queue for single-consumer processing.
Enqueue(queue string, data any)
// Wait blocks until locally-initiated operations complete. For in-memory
// implementations, this means all handlers have finished. For distributed
// implementations, this means tasks have been sent to the remote system.
Wait(ctx context.Context) error
}
WorkQueue provides task queue with single-consumer semantics. Each enqueued task is processed by exactly one worker.
func FromContext ¶
FromContext retrieves the work queue from a context.
type WorkQueuePlugin ¶
type WorkQueuePlugin struct {
WorkQueue
}
WorkQueuePlugin provides access to a work queue for plugins and components.
func Plugin ¶
func Plugin(wq WorkQueue) *WorkQueuePlugin
Plugin registers a workqueue with a Prefab server for use by other plugins. The queue can be retrieved from the request context using FromContext.
func (*WorkQueuePlugin) ServerOptions ¶
func (p *WorkQueuePlugin) ServerOptions() []prefab.ServerOption
From prefab.OptionProvider.