locks

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: May 19, 2022 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LockCollection    = "locks"
	FieldID           = "id"
	FieldOwner        = "owner"
	FieldResource     = "resource"
	FieldAcquiredTime = "acquiredTime"
	FieldUpdatedAt    = "updatedAt"
	FieldExpiry       = "expiry"
)

Variables

This section is empty.

Functions

func Retry

func Retry(ctx context.Context, action func() error, conditionalInterval RetryInterval) error

Retry executes action with retries

Types

type Lock

type Lock struct {
	ID           string     `json:"id"`
	Resource     string     `json:"resource"`
	Owner        string     `json:"owner"`
	AcquiredTime *time.Time `json:"acquiredTime"`
	UpdatedAt    *time.Time `json:"updatedAt"`
	Expiry       *time.Time `json:"expiry"`
}

func (*Lock) Expired

func (l *Lock) Expired(renewExpiry *time.Duration) bool

type LockOption

type LockOption interface {
	Apply(options *LockOptions)
}

type LockOptions

type LockOptions struct {
	Owner       string
	Expiry      *time.Duration
	RenewExpiry *time.Duration
	RetryOption WithRetry
}

type Locker

type Locker interface {
	Lock(ctx context.Context, resource string, options ...LockOption) (*Lock, error)
	Unlock(ctx context.Context, lock *Lock) error
	Renew(ctx context.Context, lock *Lock) error
}

type MockedLocker

type MockedLocker struct {
	mock.Mock
}

func (*MockedLocker) Lock

func (m *MockedLocker) Lock(ctx context.Context, resource string, options ...LockOption) (*Lock, error)

CreateFailedReloadRecord mock CreateFailedReloadRecord in ReloadService

func (*MockedLocker) Renew

func (m *MockedLocker) Renew(ctx context.Context, lock *Lock) error

func (*MockedLocker) Unlock

func (m *MockedLocker) Unlock(ctx context.Context, lock *Lock) error

type MongoDBLocker

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

func NewMongoDBLocker

func NewMongoDBLocker(db *mongo.Database) *MongoDBLocker

func (*MongoDBLocker) Lock

func (locker *MongoDBLocker) Lock(ctx context.Context, resource string, options ...LockOption) (*Lock, error)

func (*MongoDBLocker) Renew

func (locker *MongoDBLocker) Renew(ctx context.Context, lock *Lock) error

func (*MongoDBLocker) Unlock

func (locker *MongoDBLocker) Unlock(ctx context.Context, lock *Lock) error

type RetryInterval

type RetryInterval func(retries int, lastError error) (bool, time.Duration)

type WithExpiry

type WithExpiry time.Duration

func (WithExpiry) Apply

func (expiry WithExpiry) Apply(options *LockOptions)

type WithOwner

type WithOwner string

func (WithOwner) Apply

func (option WithOwner) Apply(options *LockOptions)

type WithRenewExpiry

type WithRenewExpiry time.Duration

func (WithRenewExpiry) Apply

func (expiry WithRenewExpiry) Apply(options *LockOptions)

type WithRetry added in v1.0.1

type WithRetry RetryInterval

func (WithRetry) Apply added in v1.0.1

func (option WithRetry) Apply(options *LockOptions)

Jump to

Keyboard shortcuts

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