Adds custom retry time for lock monitors.
This commit is contained in:
parent
2f3d109b18
commit
fcd0cb7a11
18
api/lock.go
18
api/lock.go
|
@ -69,12 +69,13 @@ type Lock struct {
|
||||||
|
|
||||||
// LockOptions is used to parameterize the Lock behavior.
|
// LockOptions is used to parameterize the Lock behavior.
|
||||||
type LockOptions struct {
|
type LockOptions struct {
|
||||||
Key string // Must be set and have write permissions
|
Key string // Must be set and have write permissions
|
||||||
Value []byte // Optional, value to associate with the lock
|
Value []byte // Optional, value to associate with the lock
|
||||||
Session string // Optional, created if not specified
|
Session string // Optional, created if not specified
|
||||||
SessionName string // Optional, defaults to DefaultLockSessionName
|
SessionName string // Optional, defaults to DefaultLockSessionName
|
||||||
SessionTTL string // Optional, defaults to DefaultLockSessionTTL
|
SessionTTL string // Optional, defaults to DefaultLockSessionTTL
|
||||||
MonitorRetries int // Optional, defaults to 0 which means no retries
|
MonitorRetries int // Optional, defaults to 0 which means no retries
|
||||||
|
MonitorRetryTime time.Duration // Optional, defaults to DefaultMonitorRetryTime
|
||||||
}
|
}
|
||||||
|
|
||||||
// LockKey returns a handle to a lock struct which can be used
|
// LockKey returns a handle to a lock struct which can be used
|
||||||
|
@ -104,6 +105,9 @@ func (c *Client) LockOpts(opts *LockOptions) (*Lock, error) {
|
||||||
return nil, fmt.Errorf("invalid SessionTTL: %v", err)
|
return nil, fmt.Errorf("invalid SessionTTL: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if opts.MonitorRetryTime == 0 {
|
||||||
|
opts.MonitorRetryTime = DefaultMonitorRetryTime
|
||||||
|
}
|
||||||
l := &Lock{
|
l := &Lock{
|
||||||
c: c,
|
c: c,
|
||||||
opts: opts,
|
opts: opts,
|
||||||
|
@ -348,7 +352,7 @@ RETRY:
|
||||||
// blocking fashion so that we have a clean place to reset the retry
|
// blocking fashion so that we have a clean place to reset the retry
|
||||||
// counter if service is restored.
|
// counter if service is restored.
|
||||||
if retries > 0 && strings.Contains(err.Error(), serverError) {
|
if retries > 0 && strings.Contains(err.Error(), serverError) {
|
||||||
time.Sleep(DefaultMonitorRetryTime)
|
time.Sleep(l.opts.MonitorRetryTime)
|
||||||
retries--
|
retries--
|
||||||
opts.WaitIndex = 0
|
opts.WaitIndex = 0
|
||||||
goto RETRY
|
goto RETRY
|
||||||
|
|
Loading…
Reference in New Issue