queue

package
v1.74.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

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

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() []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.

Directories

Path Synopsis
tasks

Jump to

Keyboard shortcuts

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