Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Lock ¶
func Lock(ctx context.Context, db *sql.DB, lockName string, options ...LockOption) (<-chan error, error)
Lock gets an advisory lock from postgres and holds it until ctx is canceled. It pings the db connection at a regular interval to keep it from timing out. If the lock is unavailable and "WithTimeout" is set, it will continue trying until it either times out or obtains a lock. Returns an error channel that will receive an error when the lock is released.
Types ¶
type LockOption ¶
type LockOption func(*lockOpts)
LockOption is an optional value for Lock
func WithPingInterval ¶
func WithPingInterval(pingInterval time.Duration) LockOption
WithPingInterval sets the interval for Lock to ping the connection. Default is 10 seconds.
func WithTimeout ¶
func WithTimeout(timeout time.Duration) LockOption
WithTimeout sets a timeout for Lock to wait before giving up on getting a lock. When unset, Lock will error out immediately if the lock is unavailable.
Click to show internal directories.
Click to hide internal directories.