queue

package
v1.76.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EnqueueOption

type EnqueueOption func(*EnqueueOptions)

EnqueueOption is a functional option for configuring Enqueue.

func WithOnDone

func WithOnDone(onDone func()) EnqueueOption

WithOnDone registers a callback invoked after the task completes successfully.

func WithUnique

func WithUnique() EnqueueOption

WithUnique ensures that the task will not be enqueued if there are more than 1 same task(by string) in the queue.

func WithWait

func WithWait(wg *sync.WaitGroup) EnqueueOption

WithWait specifies a WaitGroup to track task completion.

type EnqueueOptions

type EnqueueOptions struct {
	// contains filtered or unexported fields
}

EnqueueOptions configures task enqueuing behavior.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service manages a set of named task queues. It provides methods to enqueue tasks, stop individual queues, or stop all queues.

func NewService

func NewService(logger *log.Logger) *Service

NewService creates a new Service with the given context. The context is used for all queues created by the Service.

func (*Service) Dump

func (s *Service) Dump(include ...string) []byte

Dump creates dump of all queues

func (*Service) Enqueue

func (s *Service) Enqueue(ctx context.Context, queueName string, task Task, opts ...EnqueueOption)

Enqueue adds a task to the specified queue, creating and starting the queue if it doesn't exist. It ensures thread-safety using a mutex and propagates the Service's context to the queue.

Context Hierarchy: - ctx: Task-specific context for cascade cancellation (e.g., parent task context) - w.ctx: Service-level context for lifecycle management (queue shutdown) The queue uses w.ctx for its processing loop, but individual tasks use their own ctx.

func (*Service) Remove

func (s *Service) Remove(name string)

Remove stops and removes the named queue. If the queue doesn’t exist, it’s a no-op.

func (*Service) Stop

func (s *Service) Stop()

Stop stops and removes all queues. It ensures all queues are gracefully shut down.

type Task

type Task interface {
	String() string
	Execute(ctx context.Context) error // Executes the task, returning an error if it fails
}

Task defines the interface for executable tasks.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL