Documentation
¶
Overview ¶
Package pglock is a payforge.Locker that holds across instances, with a PostgreSQL transaction-scoped advisory lock.
Lock opens a transaction on a connection of its own and takes pg_advisory_xact_lock on a 64-bit hash of the key; unlock rolls the transaction back, which releases the lock. The work under the lock runs on other connections; the transaction exists only to hold the lock. Because the lock belongs to a transaction rather than a session, it cannot outlive its connection: a connection that breaks releases it, and it is never left held on a connection returned to the pool.
Set the same Locker on payforge.Lifecycle.Locker, the payforge Stripe client's Config.Locker and billing's configs, so webhooks and checkouts for one organization exclude each other. The lock is not reentrant: never take a key while already holding it.
It is PostgreSQL only, which is why it is a package of its own: the rest of billing runs on any Ent dialect.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Locker ¶
type Locker struct {
// contains filtered or unexported fields
}
Locker implements payforge.Locker on PostgreSQL.
func New ¶
New returns a Locker on db, which must be PostgreSQL. A failure to release a lock, which the database also releases when the connection ends, is logged to logger, or slog.Default() when it is nil. New panics on a nil db, a programming error.
Each held lock uses one connection from db's pool until it is released, so size the pool for the concurrent webhook deliveries and checkouts plus the work they do.