Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1890,6 +1890,10 @@ var errNoDriverDBPool = errors.New("driver must have non-nil database pool to us
// provided context is used for the underlying Postgres insert and can be used
// to cancel the operation or apply a timeout.
//
// If the application already holds a transaction on a pool limited to one
// connection, use InsertTx with that transaction instead; Insert opens its own
// transaction and waits for a pool connection.
//
// jobRow, err := client.Insert(insertCtx, MyArgs{}, nil)
// if err != nil {
// // handle error
Expand Down
7 changes: 7 additions & 0 deletions riverdriver/riversqlite/river_sqlite_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
// errors is to set the maximum pool size to one connection like
// `dbPool.SetMaxOpenConns(1)`.
//
// With a single-connection pool, insert hooks and middleware must not query
// the same pool while an insert is running: the insert holds its connection
// until they return, so their query can wait indefinitely for that connection.
// Likewise, application code that already holds a transaction should use
// `Client.InsertTx` or `Client.InsertManyTx` with that transaction instead of
// `Client.Insert` or `Client.InsertMany`.
//
// A known deficiency in this driver compared to Postgres is that due to
// limitations in sqlc, it performs operations like completion and `InsertMany`
// one row at a time instead of in batches. This means that it's slower than the
Expand Down
8 changes: 8 additions & 0 deletions rivertype/river_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ type Hook interface {
}

// HookInsertBegin is an interface to a hook that runs before job insertion.
// The hook runs synchronously as part of the insert operation and does not
// receive the insert transaction. With a pool limited to one connection, a
// hook that queries the same pool can block waiting for the connection held by
// the insert until its context is canceled.
type HookInsertBegin interface {
Hook

Expand Down Expand Up @@ -548,6 +552,10 @@ type Plugin interface {

// JobInsertMiddleware provides an interface for middleware that integrations
// can use to encapsulate common logic around job insertion.
// Middleware runs synchronously around the insert operation. With a
// single-connection pool, querying the same pool from middleware can block
// until the insert releases its connection, which cannot happen until the
// middleware returns.
//
// Implementations should embed river.JobMiddlewareDefaults to inherit default
// implementations for phases where no custom code is needed, and for forward
Expand Down