Documentation
¶
Overview ¶
Package stdriverfx provides River clients that enqueue, work, and read jobs, for either edition of River: the caller picks the client's type with the function that builds it (see Provide). It builds on open-source River only, and never imports River Pro, so it builds without River Pro's license key. It is the second version of package stdriverfx, at the v2 path, which apps can adopt next to the first.
River's tables live in their own PostgreSQL schema (Config.Schema), which the app's migrations create, so River's own migrator never runs here.
Two clients are provided, named like the connection pools they run on: the "rw" client inserts jobs, with InsertTx in the transaction of the request, and works them once a worker is registered with WithWorker; the "ro" client only reads job state.
Workers log with stdctx.Log(ctx): each job attempt has a logger in its context, whose lines River also stores with the attempt for the River UI.
Index ¶
- func CompleteTx[T river.JobArgs](ctx context.Context, pool *pgxpool.Pool, job *river.Job[T], ...) error
- func NewClient(pool *pgxpool.Pool, cfg *river.Config) (*river.Client[pgx.Tx], error)
- func Provide[C Client](newClient NewClientFunc[C]) fx.Option
- func ProvideWorker[T river.JobArgs](newf any) fx.Option
- func WithWorker[T river.JobArgs]() fx.Option
- type Client
- type Config
- type NewClientFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompleteTx ¶
func CompleteTx[T river.JobArgs]( ctx context.Context, pool *pgxpool.Pool, job *river.Job[T], fn func(context.Context, pgx.Tx) error, ) error
CompleteTx runs fn in a transaction on pool, and completes job in that same transaction, so the job's writes and its completion commit together, or neither does. Workers that write to the database return its result from Work.
It works for clients of either edition: River completes the job with the driver of the client in ctx, the one that works the job. The driver type passed to river.JobCompleteTx only names the transaction's type.
func Provide ¶
func Provide[C Client](newClient NewClientFunc[C]) fx.Option
Provide wires the module: the "rw" and "ro" clients, which newClient builds as C, on River's tables in the configured schema, from the "rw" and "ro" pools. It builds them even when nothing else depends on them, so the "rw" client always works the registered workers. Pass NewClient for open-source River's clients.
func ProvideWorker ¶
ProvideWorker provides the worker that newf, a constructor, builds as a river.Worker[T], and registers it with WithWorker.
Types ¶
type Client ¶
type Client interface {
Start(ctx context.Context) error
Stop(ctx context.Context) error
StopAndCancel(ctx context.Context) error
}
Client is what the module needs of a client to start and stop it with the app. Open-source River's client implements it, and so does River Pro's, which embeds it.
type Config ¶
type Config struct {
// Schema is the PostgreSQL schema of River's tables. River's own migrator
// never runs, so it must be the schema the app's migrations put them in.
Schema string `env:"SCHEMA" envDefault:"river"`
// MaxWorkers is how many jobs of the default queue this process works
// concurrently.
MaxWorkers int `env:"MAX_WORKERS" envDefault:"10"`
// StopTimeout is how long shutdown waits for running jobs to finish before
// cancelling them.
StopTimeout time.Duration `env:"STOP_TIMEOUT" envDefault:"5s"`
}
Config configures the clients, from the environment with the STDRIVER_ prefix.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
testmigrate
Package testmigrate migrates the test databases of package stdriverfx with River's own migrations, into the schema the clients use by default.
|
Package testmigrate migrates the test databases of package stdriverfx with River's own migrations, into the schema the clients use by default. |
|
Package stdrivertest waits, in tests, for the jobs that River clients work, and reads what they recorded.
|
Package stdrivertest waits, in tests, for the jobs that River clients work, and reads what they recorded. |