Package list golang-github-go-kit-kit / 8cb3665
Split invalidateOnError flag and timeout Yuri Shkuro 4 years ago
3 changed file(s) with 10 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
5757
5858 // Sad path. Something's gone wrong in sd.
5959 c.logger.Log("err", event.Err)
60 if c.options.invalidateOnErrorTimeout == nil {
60 if !c.options.invalidateOnError {
6161 return // keep returning the last known endpoints on error
6262 }
6363 if c.err != nil {
6565 }
6666 c.err = event.Err
6767 // 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)
6969 return
7070 }
7171
8585 c = map[string]io.Closer{"a": ca, "b": cb}
8686 f = func(instance string) (endpoint.Endpoint, io.Closer, error) { return endpoint.Nop, c[instance], nil }
8787 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 })
8992 )
9093
9194 timeNow := time.Now()
5151 // valid resource instances, the normal operation is resumed.
5252 func InvalidateOnError(timeout time.Duration) EndpointerOption {
5353 return func(opts *endpointerOptions) {
54 opts.invalidateOnErrorTimeout = &timeout
54 opts.invalidateOnError = true
55 opts.invalidateTimeout = timeout
5556 }
5657 }
5758
5859 type endpointerOptions struct {
59 invalidateOnErrorTimeout *time.Duration
60 invalidateOnError bool
61 invalidateTimeout time.Duration
6062 }
6163
6264 // DefaultEndpointer implements an Endpointer interface.