riverqueue

package
v0.0.0-...-4a1d7bd Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package riverqueue implements background job processing for document completion events using River, a PostgreSQL-native job queue. See docs/backend/worker-queue-guide.md for architecture and flow diagrams.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DocumentCompletedArgs

type DocumentCompletedArgs struct {
	DocumentID string `json:"document_id"`
}

DocumentCompletedArgs are the arguments for the document completed job.

func (DocumentCompletedArgs) InsertOpts

func (DocumentCompletedArgs) InsertOpts() river.InsertOpts

InsertOpts returns insert-time options including deduplication.

func (DocumentCompletedArgs) Kind

Kind returns the unique job kind identifier.

type DocumentCompletedWorker

type DocumentCompletedWorker struct {
	river.WorkerDefaults[DocumentCompletedArgs]
	// contains filtered or unexported fields
}

DocumentCompletedWorker processes document completion jobs.

func (*DocumentCompletedWorker) Timeout

Timeout returns the maximum duration for processing a single job.

func (*DocumentCompletedWorker) Work

Work executes the document completion handler with defensive panic recovery.

type Notifier

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

Notifier implements port.DocumentCompletionNotifier using River. It persists the document update and enqueues the completion job atomically within the same PostgreSQL transaction.

func (*Notifier) PersistAndNotify

func (n *Notifier) PersistAndNotify(ctx context.Context, doc *entity.Document) error

PersistAndNotify updates the document and enqueues a completion job in a single transaction.

type RiverService

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

RiverService manages the River client lifecycle and exposes the notifier.

func New

func New(
	ctx context.Context,
	pool *pgxpool.Pool,
	cfg config.WorkerConfig,
	handler port.DocumentCompletedHandler,
	docUpdater documentUpdater,
) (*RiverService, error)

New creates a RiverService: runs migrations, registers the worker, and builds the River client. When cfg.Enabled is false the client operates in insert-only mode (no queue processing).

func (*RiverService) Notifier

Notifier returns the DocumentCompletionNotifier for use by the document service.

func (*RiverService) Start

func (r *RiverService) Start(ctx context.Context) error

Start begins processing jobs. No-op when workers are disabled (insert-only mode).

func (*RiverService) Stop

func (r *RiverService) Stop(ctx context.Context) error

Stop gracefully shuts down the River client. No-op when workers are disabled.

Jump to

Keyboard shortcuts

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