Split invalidateOnError flag and timeout
Yuri Shkuro
4 years ago
57 | 57 |
|
58 | 58 |
// Sad path. Something's gone wrong in sd.
|
59 | 59 |
c.logger.Log("err", event.Err)
|
60 | |
if c.options.invalidateOnErrorTimeout == nil {
|
|
60 |
if !c.options.invalidateOnError {
|
61 | 61 |
return // keep returning the last known endpoints on error
|
62 | 62 |
}
|
63 | 63 |
if c.err != nil {
|
|
65 | 65 |
}
|
66 | 66 |
c.err = event.Err
|
67 | 67 |
// set new deadline to invalidate Endpoints unless non-error Event is received
|
68 | |
c.invalidateDeadline = c.timeNow().Add(*c.options.invalidateOnErrorTimeout)
|
|
68 |
c.invalidateDeadline = c.timeNow().Add(c.options.invalidateTimeout)
|
69 | 69 |
return
|
70 | 70 |
}
|
71 | 71 |
|
85 | 85 |
c = map[string]io.Closer{"a": ca, "b": cb}
|
86 | 86 |
f = func(instance string) (endpoint.Endpoint, io.Closer, error) { return endpoint.Nop, c[instance], nil }
|
87 | 87 |
timeOut = 100 * time.Millisecond
|
88 | |
cache = newEndpointCache(f, log.NewNopLogger(), endpointerOptions{invalidateOnErrorTimeout: &timeOut})
|
|
88 |
cache = newEndpointCache(f, log.NewNopLogger(), endpointerOptions{
|
|
89 |
invalidateOnError: true,
|
|
90 |
invalidateTimeout: timeOut,
|
|
91 |
})
|
89 | 92 |
)
|
90 | 93 |
|
91 | 94 |
timeNow := time.Now()
|
51 | 51 |
// valid resource instances, the normal operation is resumed.
|
52 | 52 |
func InvalidateOnError(timeout time.Duration) EndpointerOption {
|
53 | 53 |
return func(opts *endpointerOptions) {
|
54 | |
opts.invalidateOnErrorTimeout = &timeout
|
|
54 |
opts.invalidateOnError = true
|
|
55 |
opts.invalidateTimeout = timeout
|
55 | 56 |
}
|
56 | 57 |
}
|
57 | 58 |
|
58 | 59 |
type endpointerOptions struct {
|
59 | |
invalidateOnErrorTimeout *time.Duration
|
|
60 |
invalidateOnError bool
|
|
61 |
invalidateTimeout time.Duration
|
60 | 62 |
}
|
61 | 63 |
|
62 | 64 |
// DefaultEndpointer implements an Endpointer interface.
|