Documentation ¶
Index ¶
- func RunFuncInLock(ctx context.Context, key string, ttl int, fn func()) (time.Duration, error)
- func RunJobInLock(ctx context.Context, key string, ttl int, job Job) (time.Duration, error)
- type ELocker
- func (e *ELocker) Close() error
- func (e *ELocker) KeyPrefix(key string) string
- func (e *ELocker) Lock(ctx context.Context, key string, ttl int) error
- func (e *ELocker) MonitorLocks()
- func (e *ELocker) RunFuncInLock(ctx context.Context, key string, ttl int, fn func()) (time.Duration, error)
- func (e *ELocker) RunJobInLock(ctx context.Context, key string, ttl int, job Job) (time.Duration, error)
- func (e *ELocker) Unlock(ctx context.Context, key string) error
- type Job
- type Opt
- func WithMaxHeldTime(maxHeldTime time.Duration) Opt
- func WithMonitorTicks(monitorTicks time.Duration) Opt
- func WithPrefix(prefix string) Opt
- func WithRandomSleep(min, max time.Duration) Opt
- func WithSuccessCallback(successCallback func(string)) Opt
- func WithTimeoutCallback(timeoutFunc func(string, time.Duration)) Opt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunFuncInLock ¶
Types ¶
type ELocker ¶
type ELocker struct {
// contains filtered or unexported fields
}
func NewELocker ¶
NewELocker creates a new ELocker instance with the given etcd client and options.
func (*ELocker) Lock ¶
Lock attempts to acquire a lock with the specified key and TTL (time-to-live).
func (*ELocker) MonitorLocks ¶
func (e *ELocker) MonitorLocks()
MonitorLocks runs a loop that periodically checks all acquired locks and releases those that have exceeded the maximum held duration.
func (*ELocker) RunFuncInLock ¶
func (e *ELocker) RunFuncInLock(ctx context.Context, key string, ttl int, fn func()) (time.Duration, error)
RunFuncInLock executes a function while holding a lock with the specified key and TTL.
type Opt ¶
type Opt func(*ELocker)
func WithMaxHeldTime ¶
WithMaxHeldTime is an option to set the maximum duration a lock can be held before it is automatically released. Only used in Lock/Unlock.
func WithMonitorTicks ¶
WithMonitorTicks is an option to set the duration between lock monitor ticks.
func WithPrefix ¶
func WithRandomSleep ¶
WithRandomSleep is an option to set the random sleep between lock acquisitions. Only used in RunInLock.