lock

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrResourceLocked    = errors.New("resource is locked")
	ErrResourceNotLocked = errors.New("resource is not locked")
)

Functions

This section is empty.

Types

type InMem

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

func NewInMem

func NewInMem() *InMem

func (*InMem) ForceUnlockAfter

func (l *InMem) ForceUnlockAfter(duration time.Duration)

func (*InMem) IsLocked

func (l *InMem) IsLocked(name string) bool

func (*InMem) Lock

func (l *InMem) Lock(name string) error

func (*InMem) Unlock

func (l *InMem) Unlock(name string) error

type Lock

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

func NewLock

func NewLock(locker Locker, forceUnlockAfterSec int) *Lock

func (*Lock) IsLocked

func (l *Lock) IsLocked(name string) bool

func (*Lock) Lock

func (l *Lock) Lock(name string) error

Lock locks the service by its KindNamespaceName It returns an error if the service is already locked

func (*Lock) Unlock added in v0.3.0

func (l *Lock) Unlock(name string) error

Unlock unlocks the service by its KindNamespaceName It returns an error if the service is not locked

type Locker

type Locker interface {
	// Lock locks the resource by its name
	// It returns an error if the resource is already locked
	//
	// Example:
	//   Lock("Deployment/my-namespace/my-deployment")
	//
	// This will lock the resource Deployment/my-namespace/my-deployment if it's not already locked
	Lock(name string) error
	// IsLocked checks if the resource is locked
	//
	// Example:
	//   IsLocked("Deployment/my-namespace/my-deployment")
	//
	// This will return true if the resource Deployment/my-namespace/my-deployment is locked
	IsLocked(name string) bool
	// Unlock unlocks the resource by its name
	// It returns an error if the resource is not locked
	//
	// Example:
	//   Unlock("Deployment/my-namespace/my-deployment")
	//
	// This will unlock the resource Deployment/my-namespace/my-deployment if it's locked
	Unlock(name string) error
	// ForceUnlockAfter unlocks all resources after the given duration
	//
	// Example:
	//   ForceUnlockAfter(5 * time.Minute)
	//
	// This will unlock all resources after 5 minutes after a lock is acquired
	ForceUnlockAfter(duration time.Duration)
}

Jump to

Keyboard shortcuts

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