processinglock

package
v0.30.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoLock is returned when a lock can not be acquired due to normal causes.
	ErrNoLock = errors.New("advisory lock already taken or incompatible version")
)

Static errors

Functions

This section is empty.

Types

type Config

type Config struct {
	Type    Type
	Version int // Version must match the value in engine_processing_versions exactly or no lock will be obtained.
}

Config defines the parameters of the lock.

func (Config) String

func (cfg Config) String() string

String returns the string representation of Config.

type Conn

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

Conn allows using locked transactions over a single connection.

func (*Conn) BeginTx

func (c *Conn) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)

BeginTx will start a new transaction.

func (*Conn) Close

func (c *Conn) Close() error

Close returns the connection to the pool.

func (*Conn) Exec

func (c *Conn) Exec(ctx context.Context, stmt *sql.Stmt, args ...interface{}) (sql.Result, error)

Exec will call ExecContext on the statement wrapped in a locked transaction.

func (*Conn) ExecWithoutLock

func (c *Conn) ExecWithoutLock(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

ExecWithoutLock will run a query directly on the connection (no Tx or locking).

type Lock

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

A Lock is used to start "locked" transactions.

func NewLock

func NewLock(ctx context.Context, db *sql.DB, cfg Config) (*Lock, error)

NewLock will return a new Lock for the given Config.

func (*Lock) BeginTx

func (l *Lock) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)

BeginTx will start a transaction with the appropriate lock in place (based on Config).

func (*Lock) BeginTxWithState added in v0.30.0

func (l *Lock) BeginTxWithState(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, *State, error)

BeginTxWithState will start a transaction, returning a State object.

func (*Lock) Conn

func (l *Lock) Conn(ctx context.Context) (*Conn, error)

Conn returns a new connection from the DB pool.

Note: No version checking/locking is done until a transaction is started.

func (*Lock) Exec

func (l *Lock) Exec(ctx context.Context, stmt *sql.Stmt, args ...interface{}) (sql.Result, error)

Exec will run ExecContext on the statement, wrapped in a locked transaction.

type State added in v0.30.0

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

State manages the state value for a processing lock.

func (*State) Load added in v0.30.0

func (s *State) Load(ctx context.Context, v interface{}) error

Load will load the JSON state from the database.

func (*State) Save added in v0.30.0

func (s *State) Save(ctx context.Context, v interface{}) error

Save will save the JSON state to the database, taking care to ensure that existing unknown fields are preserved.

type Type

type Type string

Type indicates the lock type. For TypeMessage, the RegionID is used.

const (
	TypeEscalation   Type = "escalation"
	TypeHeartbeat    Type = "heartbeat"
	TypeNPCycle      Type = "np_cycle"
	TypeRotation     Type = "rotation"
	TypeSchedule     Type = "schedule"
	TypeStatusUpdate Type = "status_update"
	TypeVerify       Type = "verify"
	TypeMessage      Type = "message"
	TypeCleanup      Type = "cleanup"
	TypeMetrics      Type = "metrics"
)

Recognized types

Jump to

Keyboard shortcuts

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