mirror of
https://github.com/status-im/consul.git
synced 2025-02-16 15:47:21 +00:00
Adds custom retry time for lock monitors.
This commit is contained in:
parent
86e6230de6
commit
c2a8fee76c
@ -75,6 +75,7 @@ type LockOptions struct {
|
|||||||
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…
x
Reference in New Issue
Block a user