queue

package
v0.0.0-...-5106b98 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarkWorkerPersistedFailure

func MarkWorkerPersistedFailure(ctx context.Context, code, category string)

func MarkWorkerSkipped

func MarkWorkerSkipped(ctx context.Context)

Types

type Client

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

Client wraps River so callers can enqueue jobs on the shared Postgres runtime without depending on driver-specific setup details.

func New

func New(pool *pgxpool.Pool, config *Config) (*Client, error)

New creates a queue client backed by the shared pgx pool.

func NewEnqueueOnly

func NewEnqueueOnly(pool *pgxpool.Pool) (*Client, error)

NewEnqueueOnly creates a queue client that can enqueue River jobs inside SQL transactions, but does not start any River workers to execute jobs.

func NewWorkerHost

func NewWorkerHost(pool *pgxpool.Pool, config *WorkerHostConfig) (*Client, error)

NewWorkerHost creates a River client that can work jobs when registrars are provided, and otherwise falls back to enqueue-only behavior without running any River workers.

func (*Client) CancelJob

func (c *Client) CancelJob(ctx context.Context, tx postgres.DBTX, id int64) error

CancelJob uses River's transactional state machine and running-job notification. A running job receives cancellation intent, not a claim that it has stopped.

func (*Client) Start

func (c *Client) Start(ctx context.Context) error

Start enables worker execution when the client is configured with queues.

func (*Client) Stop

func (c *Client) Stop(ctx context.Context) error

Stop gracefully shuts down worker execution when it was started.

func (*Client) WorkerLivenessSnapshot

func (c *Client) WorkerLivenessSnapshot(now time.Time) []WorkerLivenessMetric

WorkerLivenessSnapshot reports configured worker queue liveness without exposing job payloads.

type Config

type Config struct {
	Queues       map[string]river.QueueConfig
	PeriodicJobs []*river.PeriodicJob
	Workers      *river.Workers
	Logger       *slog.Logger
	RetryPolicy  river.ClientRetryPolicy
}

Config configures the internal River-backed queue client.

type EnqueueRequest

type EnqueueRequest struct {
	Args  JobArgs
	Queue string
	// InitiatingAccount serializes account-bound admission with account removal.
	// Leave empty for organization/system work that must survive its initiator.
	InitiatingAccount slug.Slug
}

EnqueueRequest describes a job that should become visible when tx commits.

type Enqueuer

type Enqueuer interface {
	EnqueueTx(ctx context.Context, tx postgres.DBTX, req EnqueueRequest) (QueuedJob, error)
}

Enqueuer is the service-facing port for durable background work.

func NewEnqueuer

func NewEnqueuer(client *Client) Enqueuer

type JobArgs

type JobArgs interface {
	Kind() string
	InsertOpts() river.InsertOpts
}

JobArgs identifies a durable River job payload and its enqueue options.

type QueuedJob

type QueuedJob struct {
	ID    int64 `json:"-"`
	Kind  string
	Queue string
	State string
}

QueuedJob reports the enqueue outcome, not job completion.

type WorkerHostConfig

type WorkerHostConfig struct {
	Queues       map[string]river.QueueConfig
	PeriodicJobs []*river.PeriodicJob
	Registrars   []WorkerRegistrar
	Logger       *slog.Logger
	RetryPolicy  river.ClientRetryPolicy
}

WorkerHostConfig configures a worker-capable River client.

type WorkerLivenessMetric

type WorkerLivenessMetric struct {
	Queue            string
	ActiveWorkers    int64
	MaxWorkers       int64
	LastHeartbeatAge time.Duration
}

WorkerLivenessMetric describes queue-worker liveness for metrics collection.

type WorkerRegistrar

type WorkerRegistrar interface {
	Register(*river.Workers) error
}

WorkerRegistrar registers one or more River workers on a shared bundle.

Jump to

Keyboard shortcuts

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