store

package
v3.27.2 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AcquireLockResult

type AcquireLockResult struct {
	LockedBy       string
	LeaseExpiresAt time.Time
}

AcquireLockResult contains the result of a lock acquisition attempt.

type LockStatus

type LockStatus struct {
	Locked         bool
	LockedBy       *string
	LeaseExpiresAt *time.Time
	UpdatedAt      *time.Time
}

LockStatus represents the current status of a lock.

type LockStore

type LockStore interface {
	// CreateLockTable creates the lock table if it doesn't exist. Implementations should ensure
	// that this operation is idempotent.
	CreateLockTable(ctx context.Context, db *sql.DB) error
	// TableExists checks if the lock table exists.
	TableExists(ctx context.Context, db *sql.DB) (bool, error)
	// AcquireLock attempts to acquire a lock for the given lockID.
	AcquireLock(ctx context.Context, db *sql.DB, lockID int64, lockedBy string, leaseDuration time.Duration) (*AcquireLockResult, error)
	// ReleaseLock releases a lock held by the current instance.
	ReleaseLock(ctx context.Context, db *sql.DB, lockID int64, lockedBy string) (*ReleaseLockResult, error)
	// UpdateLease updates the lease expiration time for a lock (heartbeat).
	UpdateLease(ctx context.Context, db *sql.DB, lockID int64, lockedBy string, leaseDuration time.Duration) (*UpdateLeaseResult, error)
	// CheckLockStatus checks the current status of a lock.
	CheckLockStatus(ctx context.Context, db *sql.DB, lockID int64) (*LockStatus, error)
	// CleanupStaleLocks removes any locks that have expired using server time. Returns the list of
	// lock IDs that were cleaned up, if any.
	CleanupStaleLocks(ctx context.Context, db *sql.DB) ([]int64, error)
}

LockStore defines the interface for storing and managing database locks.

func NewPostgres

func NewPostgres(tableName string) (LockStore, error)

NewPostgres creates a new Postgres-based LockStore.

type ReleaseLockResult

type ReleaseLockResult struct {
	LockID int64
}

ReleaseLockResult contains the result of a lock release.

type UpdateLeaseResult

type UpdateLeaseResult struct {
	LeaseExpiresAt time.Time
}

UpdateLeaseResult contains the result of a lease update.

Jump to

Keyboard shortcuts

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