dblock

package
v0.0.0-...-ea697fb Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: AGPL-3.0, Apache-2.0, CC-BY-SA-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TrashSweep         = &DBLocker{key: 10001}
	ContainerLogSweep  = &DBLocker{key: 10002}
	KeepBalanceService = &DBLocker{key: 10003} // keep-balance service in periodic-sweep loop
	KeepBalanceActive  = &DBLocker{key: 10004} // keep-balance sweep in progress (either -once=true or service loop)
	Dispatch           = &DBLocker{key: 10005} // any dispatcher running
	RailsMigrations    = &DBLocker{key: 10006}
)

Functions

This section is empty.

Types

type DBLocker

type DBLocker struct {
	// contains filtered or unexported fields
}

DBLocker uses pg_advisory_lock to maintain a cluster-wide lock for a long-running task like "do X every N seconds".

func (*DBLocker) Check

func (dbl *DBLocker) Check() bool

Check confirms that the lock is still active (i.e., the session is still alive), and re-acquires if needed. Panics if Lock is not acquired first.

Returns false if the context passed to Lock() is canceled before the lock is confirmed or reacquired.

func (*DBLocker) Lock

func (dbl *DBLocker) Lock(ctx context.Context, getdb func(context.Context) (*sqlx.DB, error)) bool

Lock acquires the advisory lock, waiting/reconnecting if needed.

Returns false if ctx is canceled before the lock is acquired.

func (*DBLocker) Unlock

func (dbl *DBLocker) Unlock()

Jump to

Keyboard shortcuts

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