Documentation ¶
Index ¶
- Constants
- Variables
- type Client
- type Lock
- func (l *Lock) Acquire(ctx context.Context, id string) (lockID string, err error)
- func (l *Lock) Close(ctx context.Context)
- func (l *Lock) Init(ctx context.Context, lockClient Client, lockPurger Purger)
- func (l *Lock) Lock(resourceID string) (lockID string, err error)
- func (l *Lock) Unlock(lockID string) error
- type Purger
Constants ¶
const PurgerPeriod = 5 * time.Minute
PurgerPeriod is the time period between expired lock purges
const TTL = 30
TTL is the 'time to live' for a lock in number of seconds
Variables ¶
var AcquireMaxRetries = 10
AcquireMaxRetries is the maximum number of locking retries by the Acquire lock, discounting the first attempt
var AcquirePeriod = 250 * time.Millisecond
AcquirePeriod is the time period between acquire lock retries
var ErrAcquireMaxRetries = errors.New("cannot acquire lock, maximum number of retries has been reached")
ErrAcquireMaxRetries is an error returned when acquire fails after retrying to lock a resource 'AcquireMaxRetries' times
var ErrMongoDbClosing = errors.New("mongo db is being closed")
ErrMongoDbClosing is an error returned because MongoDB is being closed
var GenerateTimeID = func() int { return time.Now().Nanosecond() }
GenerateTimeID returns the current timestamp in nanoseconds
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface { XLock(resourceName, lockID string, ld lock.LockDetails) error Unlock(lockID string) ([]lock.LockStatus, error) }
Client defines the lock Client methods from mongo-lock
type Lock ¶
type Lock struct { Client Client CloserChannel chan struct{} Purger Purger WaitGroup *sync.WaitGroup Resource string }
Lock is a MongoDB lock for a resource
func (*Lock) Acquire ¶
Acquire tries to lock the provided id. If the resource is already locked, this function will block until the existing lock is released, at which point we acquire the lock and return.
func (*Lock) Init ¶
Init initialises a lock with the provided client and purger, and starts the purger loop
type Purger ¶
type Purger interface {
Purge() ([]lock.LockStatus, error)
}
Purger defines the lock Purger methods from mongo-lock