pgqueue

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 23 Imported by: ? 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 Manager

type Manager struct {
	pg.PoolConn
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, pool pg.PoolConn, opts ...Opt) (_ *Manager, err error)

func (*Manager) CleanQueue

func (self *Manager) CleanQueue(ctx context.Context, name string) (result []schema.Task, err error)

CleanQueue removes up to schema.QueueCleanLimit of the queue's finished tasks, which finished longer ago than the retention period, and returns the tasks removed.

func (*Manager) CreateNextPartition

func (self *Manager) CreateNextPartition(ctx context.Context) (result string, err error)

func (*Manager) CreatePartition

func (self *Manager) CreatePartition(ctx context.Context, meta schema.PartitionMeta) (err error)

func (*Manager) CreateTask

func (self *Manager) CreateTask(ctx context.Context, queue string, meta schema.TaskMeta) (result *schema.Task, err error)

CreateTask creates a new task in a queue, and returns it.

func (*Manager) DeletePartition

func (self *Manager) DeletePartition(ctx context.Context, name string) (err error)

func (*Manager) DeleteQueue

func (self *Manager) DeleteQueue(ctx context.Context, name string) (result *schema.Queue, err error)

DeleteQueue deletes an existing queue, and returns it.

func (*Manager) DeleteTicker

func (self *Manager) DeleteTicker(ctx context.Context, name string) (result *schema.Ticker, err error)

DeleteTicker deletes an existing ticker, and returns the deleted ticker.

func (*Manager) DropDrainedPartition

func (self *Manager) DropDrainedPartition(ctx context.Context) (result string, err error)

func (*Manager) GetPartitionSeq

func (self *Manager) GetPartitionSeq(ctx context.Context) (result uint64, err error)

func (*Manager) GetQueue

func (self *Manager) GetQueue(ctx context.Context, name string) (result *schema.QueueWithStatus, err error)

GetQueue returns a queue by name.

func (*Manager) GetTask added in v1.4.3

func (self *Manager) GetTask(ctx context.Context, id uint64) (result *schema.TaskWithStatus, err error)

GetTask returns a task with its status, so it can be examined. The task isn't retained or changed.

func (*Manager) GetTicker

func (self *Manager) GetTicker(ctx context.Context, name string) (result *schema.Ticker, err error)

GetTicker returns a ticker by name.

func (*Manager) ListPartitions

func (self *Manager) ListPartitions(ctx context.Context) (result []schema.Partition, err error)

func (*Manager) ListQueueStatuses

func (self *Manager) ListQueueStatuses(ctx context.Context) (result []schema.QueueWithStatus, err error)

ListQueueStatuses returns every queue, with the number of its tasks with each status

func (*Manager) ListQueues

func (self *Manager) ListQueues(ctx context.Context, req schema.QueueListRequest) (result *schema.QueueList, err error)

ListQueues returns all queues as a list.

func (*Manager) ListTasks

func (self *Manager) ListTasks(ctx context.Context, req schema.TaskListRequest) (result *schema.TaskList, err error)

ListTasks returns all tasks with optional queue and status filtering.

func (*Manager) ListTickers

func (self *Manager) ListTickers(ctx context.Context, req schema.TickerListRequest) (result *schema.TickerList, err error)

ListTickers returns all tickers as a list.

func (*Manager) NextTask

func (self *Manager) NextTask(ctx context.Context, worker string, queues ...string) (result *schema.Task, err error)

NextTask retains a task from any of the specified queues, and returns it. If no task is available, nil is returned.

func (*Manager) NextTicker

func (self *Manager) NextTicker(ctx context.Context) (result *schema.Ticker, err error)

NextTicker returns the next due ticker of the tickers with callbacks in this process, and marks it as run now, or returns nil if none is due. The tickers of another process sharing the database aren't returned.

func (*Manager) RegisterQueue

func (self *Manager) RegisterQueue(ctx context.Context, name string, meta schema.QueueMeta, callback schema.TaskFunc) (result *schema.Queue, err error)

RegisterQueue creates a new queue, or updates an existing queue, and returns it.

func (*Manager) RegisterTicker

func (self *Manager) RegisterTicker(ctx context.Context, name string, meta schema.TickerMeta, callback schema.TaskFunc) (resultPtr *schema.Ticker, err error)

RegisterTicker creates a new ticker, or updates an existing ticker, and returns it.

func (*Manager) ReleaseTask

func (self *Manager) ReleaseTask(ctx context.Context, taskId uint64, success bool, result json.RawMessage, status *string) (resp *schema.Task, err error)

ReleaseTask releases a task, optionally marking it as failed, and returns it.

func (*Manager) Run

func (self *Manager) Run(ctx context.Context, logger *slog.Logger) error

Run runs the event loop until the context is cancelled, running the tasks of the queues, and the tickers, which have callbacks in this process. The queues and tickers of another process sharing the database are left to that process. When the context is cancelled, the running tasks are cancelled, and released as failed, so they're retried, if they have retries left. Only one event loop can run at a time.

func (*Manager) Running

func (self *Manager) Running() bool

Running reports whether the event loop is running, and listening for new tasks, so a task created afterwards is run straight away

func (*Manager) SetPartitionSeqMin added in v1.4.4

func (self *Manager) SetPartitionSeqMin(ctx context.Context, min uint64) (result uint64, err error)

SetPartitionSeqMin raises the sequence for the task table so the next task id is at least the minimum, and leaves it when it's already there. Returns the sequence's value.

func (*Manager) UnregisterQueue added in v1.4.1

func (self *Manager) UnregisterQueue(ctx context.Context, name string) (err error)

UnregisterQueue removes the task callback of the queue in this process, so this process stops running its tasks, but keeps the queue and its tasks, for other processes, or for when the queue is registered again. Tasks which are running are released when they finish. Returns ErrNotFound if the queue has no callback in this process.

func (*Manager) UpdateQueue

func (self *Manager) UpdateQueue(ctx context.Context, name string, meta schema.QueueMeta) (result *schema.Queue, err error)

UpdateQueue updates an existing queue, and returns it.

func (*Manager) UpdateTicker

func (self *Manager) UpdateTicker(ctx context.Context, name string, meta schema.TickerMeta) (result *schema.Ticker, err error)

UpdateTicker updates an existing ticker, and returns it.

type Opt

type Opt func(*opt) error

Opt configures a Manager during construction.

func WithMaintenancePeriod

func WithMaintenancePeriod(period time.Duration) Opt

WithMaintenancePeriod sets how often the maintenance ticker runs. Values less than 1 second are ignored.

func WithMeter

func WithMeter(meter metric.Meter) Opt

WithMeter sets the OpenTelemetry meter used for manager metrics.

func WithPartitionAhead

func WithPartitionAhead(ahead uint64) Opt

WithPartitionAhead sets how many partitions to create when threshold is reached.

func WithPartitionSize

func WithPartitionSize(size uint64) Opt

WithPartitionSize sets the task partition size. Values less than 1 are ignored.

func WithPartitionThreshold

func WithPartitionThreshold(threshold float64) Opt

WithPartitionThreshold sets the partition creation threshold in the range (0,1].

func WithRetention

func WithRetention(retention time.Duration) Opt

WithRetention sets how long finished tasks are kept, before the cleanup ticker deletes them. Zero deletes them when the ticker next runs, and negative values are ignored.

func WithSchema

func WithSchema(schemaName string) Opt

WithSchema sets the database schema names to use for all queries. If not set the default schemas are used.

func WithTracer

func WithTracer(tracer trace.Tracer) Opt

WithTracer sets the OpenTelemetry tracer used for manager spans.

func WithWorker

func WithWorker(workerName string) Opt

WithWorker sets the worker name used for manager tasks. If not set the hostname is used.

type Result

type Result struct {
	Queue  string            `json:"queue,omitempty"`
	Task   *schema.Task      `json:"task,omitempty"`
	Ticker string            `json:"ticker,omitempty"`
	Result json.RawMessage   `json:"result,omitempty"`
	Error  error             `json:"error,omitempty"`
	Trace  trace.SpanContext `json:"-"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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