Documentation
¶
Index ¶
- Constants
- type LeaderElectionHandler
- type LeaderElector
- type LeaderElectorConfig
- type Lock
- type LockQueryConfig
- type LockRepository
- type Locker
- func (l *Locker) Confirm() (bool, error)
- func (l *Locker) Hearbeat() time.Duration
- func (l *Locker) IsLocked() bool
- func (l *Locker) Lock(interval time.Duration) (bool, error)
- func (l *Locker) LockContext(ctx context.Context, interval time.Duration) (bool, error)
- func (l *Locker) LockName() string
- func (l *Locker) LockedAt() *time.Time
- func (l *Locker) Name() string
- func (l *Locker) TryLock() (bool, error)
- func (l *Locker) Ttl() time.Duration
- func (l *Locker) Unlock() (bool, error)
- type LockerConfig
- type PostgresLockRepository
- func (r *PostgresLockRepository) Create(tx *sql.Tx, name string) error
- func (r *PostgresLockRepository) CreateTable(tx *sql.Tx) error
- func (r *PostgresLockRepository) DeleteAll(tx *sql.Tx) error
- func (r *PostgresLockRepository) FindOne(tx *sql.Tx, name string) (*Lock, error)
- func (r *PostgresLockRepository) Save(tx *sql.Tx, lock *Lock) error
Constants ¶
View Source
const DefaultHeartbeat = DefaultLockTtl / 3
The defaulth heartbeat interval is 20 sec
View Source
const DefaultLockTtl = 60 * time.Second
The default TTL is 60 sec
View Source
const DefaultLockedAtField = "locked_at_ts"
View Source
const DefaultNameField = "name"
View Source
const DefaultOwnerField = "owner"
View Source
const DefaultTableName = "barn_lock"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LeaderElectionHandler ¶
type LeaderElector ¶
type LeaderElector struct {
// contains filtered or unexported fields
}
func NewLeaderElector ¶
func NewLeaderElector(config *LeaderElectorConfig) *LeaderElector
func (*LeaderElector) Start ¶
func (l *LeaderElector) Start()
func (*LeaderElector) StartContext ¶
func (l *LeaderElector) StartContext(ctx context.Context)
func (*LeaderElector) Stop ¶
func (l *LeaderElector) Stop()
type LeaderElectorConfig ¶
type LeaderElectorConfig struct {
Log *slog.Logger
Lock *Locker
Handler LeaderElectionHandler
}
type LockQueryConfig ¶
type LockRepository ¶
type LockRepository interface {
FindOne(tx *sql.Tx, name string) (*Lock, error)
Create(tx *sql.Tx, name string) error
Save(tx *sql.Tx, lock *Lock) error
}
func NewPostgresLockRepository ¶
func NewPostgresLockRepository(config ...LockQueryConfig) LockRepository
type Locker ¶
type Locker struct {
// contains filtered or unexported fields
}
Locker is the mutex entry in the database.
func NewDefaultLock ¶
func NewLockWithConfig ¶
func NewLockWithConfig(db *sql.DB, config *LockerConfig) *Locker
NewLockWithConfig create new Lock with config, during initialization config is adjusted
func (*Locker) LockContext ¶
Acquire the lock
type LockerConfig ¶
type PostgresLockRepository ¶
type PostgresLockRepository struct {
// contains filtered or unexported fields
}
func (*PostgresLockRepository) Create ¶
func (r *PostgresLockRepository) Create(tx *sql.Tx, name string) error
func (*PostgresLockRepository) CreateTable ¶
func (r *PostgresLockRepository) CreateTable(tx *sql.Tx) error
func (*PostgresLockRepository) DeleteAll ¶ added in v0.2.0
func (r *PostgresLockRepository) DeleteAll(tx *sql.Tx) error
Click to show internal directories.
Click to hide internal directories.