dblocker

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxBatchSize = 100

Variables

View Source
var Name = "DBLocker"

Name is the plugin name.

Functions

This section is empty.

Types

type DBLocker

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

DBLocker implements a simple target locker based on a relational database. The current implementation only supports MySQL officially. All functions in DBLocker are safe for concurrent use by multiple goroutines.

func New

func New(dbURI string, opts ...Opt) (*DBLocker, error)

New initializes and returns a new DBLocker target locker.

func (*DBLocker) Close

func (d *DBLocker) Close() error

Close closes the DB connection and releases resources.

func (*DBLocker) Lock

func (d *DBLocker) Lock(ctx xcontext.Context, jobID types.JobID, duration time.Duration, targets []*target.Target) error

Lock locks the given targets. See target.Locker for API details

func (*DBLocker) RefreshLocks

func (d *DBLocker) RefreshLocks(ctx xcontext.Context, jobID types.JobID, duration time.Duration, targets []*target.Target) error

RefreshLocks refreshes the locks on the given targets. See target.Locker for API details

func (*DBLocker) ResetAllLocks

func (d *DBLocker) ResetAllLocks(ctx xcontext.Context) error

ResetAllLocks resets the database and clears all locks, regardless of who owns them. This is primarily for testing, and should not be used by used in prod, this is why it is not exposed by target.Locker

func (*DBLocker) TryLock

func (d *DBLocker) TryLock(ctx xcontext.Context, jobID types.JobID, duration time.Duration, targets []*target.Target, limit uint) ([]string, error)

TryLock attempts to locks the given targets. See target.Locker for API details

func (*DBLocker) Unlock

func (d *DBLocker) Unlock(ctx xcontext.Context, jobID types.JobID, targets []*target.Target) error

Unlock unlocks the given targets. See target.Locker for API details

type Opt

type Opt func(dblocker *DBLocker)

Opt is a function type that sets parameters on the DBLocker object

func WithClock

func WithClock(value clock.Clock) Opt

WithClock option sets clock used for timestamps.

func WithDriverName

func WithDriverName(name string) Opt

WithDriverName option allows using a mysql-compatible driver (e.g. a wrapper around mysql or a syntax-compatible variant).

func WithMaxBatchSize

func WithMaxBatchSize(value int) Opt

WithMaxBatchSize option sets maximum batch size for statements.

Jump to

Keyboard shortcuts

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