river

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package river initializes River tables explicitly and composes library workers into one host-owned client. It never owns the host pool or starts/stops clients.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyMigrations added in v0.2.0

func ApplyMigrations(ctx context.Context, pool *pgxpool.Pool, schema string) error

ApplyMigrations creates schema and applies River's pending migrations. Empty schema selects public, matching New. Use the same schema for both calls.

Calls for the same database/schema serialize before any schema creation. A dedicated connection holds the advisory lock, leaving even a one-connection host pool available to the migrator. The caller retains ownership of pool.

func New

func New(ctx context.Context, pool *pgxpool.Pool, options *riverqueue.Config, jobs ...Contribution) (client *riverqueue.Client[pgx.Tx], err error)

New registers every contribution before constructing one unstarted client, then binds its producers. A failed composition consumes its contributions; discard the participating library runtimes and construct fresh ones. The input config's maps and slices are copied. An existing Workers registry may be extended during registration and must also be discarded on failure.

Types

type Binding

type Binding struct {
	Client *riverqueue.Client[pgx.Tx]
	Pool   *pgxpool.Pool
}

Binding is the final client and the exact pool used to construct it. Both are borrowed from the host: contributions must not start/stop the client or close the pool. A contribution may use Pool to verify its transactional producers address the same physical database before enabling them.

type Contribution

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

Contribution is one library's startup registration and producer binding. Copies share the same single-use identity. Libraries also guard their own lifecycle so requesting a fresh contribution cannot compose a runtime twice.

func Group

func Group(jobs ...Contribution) Contribution

Group bundles a library's own jobs with already attached components. It does not register or bind anything. Children are flattened before any composition validation, so duplicate registrations cannot hide inside a group.

func NewContribution

func NewContribution(name string, register func(context.Context, *riverqueue.Config) error, bind func(context.Context, Binding) error, abort func() error) Contribution

NewContribution describes one library's jobs. register adds workers, active queues and periodic jobs; bind attaches the final unstarted client to any request-side producers. abort must invalidate partial registration/binding and release only the library's composition resources, never the host pool. Construction is side-effect free. Nil bind/abort hooks are allowed for a stateless contribution with no producer or resources to clean up. A bind callback requires an abort callback to invalidate any partial producer binding.

Jump to

Keyboard shortcuts

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