Skip to content

Commit

Permalink
Improve documentation for insert-only clients (#375)
Browse files Browse the repository at this point in the history
Try to address #371 in that it's currently too hard to discover that an
insert-only client is possible, and how to initialize one. There is some
documentation on the `Queues` variable, but it's not that easy to find.

Here, add docs in a few other places under the principle that some docs
repetition isn't the worse thing in that it helps make these concepts
more obvious to find. We put docs in the README and package docs (which
mirror each other), along with some on the `river.Config` struct.

Fixes #371.
  • Loading branch information
brandur authored Jun 3, 2024
1 parent 15a515b commit 8edd49c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
6 changes: 6 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ const (
)

// Config is the configuration for a Client.
//
// Both Queues and Workers are required for a client to work jobs, but an
// insert-only client can be initialized by omitting Queues, and not calling
// Start for the client. Workers can also be omitted, but it's better to include
// it so River can check that inserted job kinds have a worker that can run
// them.
type Config struct {
// AdvisoryLockPrefix is a configurable 32-bit prefix that River will use
// when generating any key to acquire a Postgres advisory lock. All advisory
Expand Down
22 changes: 21 additions & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ goroutines at a time:
},
Workers: workers,
})
if err != nil {
panic(err)
}
Expand All @@ -74,6 +73,22 @@ goroutines at a time:
panic(err)
}
## Insert-only clients
It's often desirable to have a client that'll be used for inserting jobs, but
not working them. This is possible by omitting the `Queues` configuration, and
skipping the call to `Start`:
riverClient, err := river.NewClient(riverpgxv5.New(dbPool), &river.Config{
Workers: workers,
})
if err != nil {
panic(err)
}
`Workers` can also be omitted, but it's better to include it so River can check
that inserted job kinds have a worker that can run them.
## Stopping
The client should also be stopped on program shutdown:
Expand Down Expand Up @@ -112,6 +127,9 @@ See the [`InsertAndWork` example] for complete code.
- [Error and panic handling].
- [Multiple queues] to better guarantee job throughput, worker availability,
and isolation between components.
- [Periodic and cron jobs].
- [Scheduled jobs] that run automatically at their scheduled time in the
Expand All @@ -122,6 +140,8 @@ See the [`InsertAndWork` example] for complete code.
- [Subscriptions] to queue activity and statistics, providing easy hooks for
telemetry like logging and metrics.
- [Test helpers] to verify that jobs are inserted as expected.
- [Transactional job completion] to guarantee job completion commits with
other changes in a transaction.
Expand Down
17 changes: 16 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ riverClient, err := river.NewClient(riverpgxv5.New(dbPool), &river.Config{
},
Workers: workers,
})

if err != nil {
panic(err)
}
Expand All @@ -82,6 +81,22 @@ if err := riverClient.Start(ctx); err != nil {
}
```

## Insert-only clients

It's often desirable to have a client that'll be used for inserting jobs, but
not working them. This is possible by omitting the `Queues` configuration, and
skipping the call to `Start`:

riverClient, err := river.NewClient(riverpgxv5.New(dbPool), &river.Config{
Workers: workers,
})
if err != nil {
panic(err)
}

`Workers` can also be omitted, but it's better to include it so River can check
that inserted job kinds have a worker that can run them.

### Stopping

The client should also be stopped on program shutdown:
Expand Down

0 comments on commit 8edd49c

Please sign in to comment.