pglocker

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2020 License: MIT Imports: 5 Imported by: 0

README

pglocker

godoc ci

pglocker creates an advisory lock (aka named lock) on a postgresql database

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL