processinglock

package
v0.34.1 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2025 License: Apache-2.0 Imports: 15 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 int32 // 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()

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).

func (*Conn) WithTx added in v0.33.0

func (c *Conn) WithTx(ctx context.Context, txFn func(tx *sql.Tx) error) error

WithTx will run the given function in a locked transaction.

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.

func (*Lock) WithTx added in v0.31.0

func (l *Lock) WithTx(ctx context.Context, fn func(context.Context, *sql.Tx) error) error

WithTx will run the given function in a locked transaction, returning ErrNoLock immediately if the lock cannot be acquired.

func (*Lock) WithTxShared added in v0.34.0

func (l *Lock) WithTxShared(ctx context.Context, fn func(context.Context, *sql.Tx) error) error

WithTxShared will run the given function in a locked transaction that is compatible with other shared locks.

Note: This will block until it acquires the lock.

type Module added in v0.33.0

type Module interface {
	Name() string
}

Module is a processing lock module.

type SetupArgs added in v0.33.0

type SetupArgs struct {
	DB       *sql.DB
	Workers  *river.Workers
	EventBus *event.Bus
	River    *river.Client[pgx.Tx]
}

SetupArgs is a struct that contains the arguments for the setup function.

type Setupable added in v0.33.0

type Setupable interface {
	Module

	// Setup is called to configure the processing lock system. Any workers, queues, and periodic jobs should be added here.
	Setup(context.Context, SetupArgs) error
}

Setupable is an interface for types that can be set up using the job queue system.

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{}) (err 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"
	TypeCompat       Type = "compat"
	TypeSignals      Type = "signals"
)

Recognized types

type Updatable added in v0.33.0

type Updatable interface {
	Module
	UpdateAll(context.Context) error
}

Updatable is an interface for types that can be updated.

Jump to

Keyboard shortcuts

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