Help us shape the future of Go! Take the 2026 Go Developer Survey

taskqueue

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrChannelFull = errors.New("channel full (backpressure)")

Functions

This section is empty.

Types

type Config

type Config struct {
	Name        string
	Workers     int           // per priority lane (Low gets half)
	MaxAttempts int           // default 5
	BaseDelay   time.Duration // exponential retry base, default 500ms
	Logger      *slog.Logger
}

Config controls queue behavior.

type Envelope

type Envelope struct {
	ID         string          `json:"id"`
	Type       string          `json:"type"`
	Payload    json.RawMessage `json:"payload"`
	Attempt    int             `json:"attempt"`
	EnqueuedAt time.Time       `json:"enqueued_at"`
}

Envelope is the data passed to handlers.

type Handler

type Handler func(ctx context.Context, env Envelope) error

Handler processes one task.

type Priority

type Priority int8

Priority for task lanes.

const (
	High   Priority = 2
	Normal Priority = 1
	Low    Priority = 0
)

type Queue

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

Queue is the in‑process task queue.

func New

func New(cfg Config) (*Queue, error)

New creates a ready Queue (no external deps).

func (*Queue) DeadLetter

func (q *Queue) DeadLetter() <-chan Envelope

func (*Queue) Enqueue

func (q *Queue) Enqueue(ctx context.Context, taskType string, payload any) error

Enqueue adds a task at Normal priority.

func (*Queue) EnqueueAt

func (q *Queue) EnqueueAt(_ context.Context, taskType string, payload any, p Priority) error

EnqueueAt adds a task with the specified priority.

func (*Queue) Register

func (q *Queue) Register(taskType string, h Handler)

Register binds a handler to a task type.

func (*Queue) Start

func (q *Queue) Start(ctx context.Context) error

Start begins processing workers. Blocks until ctx is canceled.

Directories

Path Synopsis
Package nexssflow exposes the in-process task queue to Nexss Flow.
Package nexssflow exposes the in-process task queue to Nexss Flow.

Jump to

Keyboard shortcuts

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