-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
remember last error and keep internal buffer of last N errors. fixed … #46
base: master
Are you sure you want to change the base?
Conversation
circuitbreaker.go
Outdated
@@ -153,12 +159,17 @@ func NewBreakerWithOptions(options *Options) *Breaker { | |||
options.WindowBuckets = DefaultWindowBuckets | |||
} | |||
|
|||
if options.ErrorHistoryDepth == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if it's < 0? Should this be uint?
circuitbreaker.go
Outdated
} | ||
|
||
// Error returns last error from internal buffer | ||
func (cb *Breaker) Error() error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe rename to LastError
to avoid confusion with error interface
circuitbreaker.go
Outdated
|
||
// Errors returns all errors from internal buffer | ||
func (cb *Breaker) Errors() (errors []error) { | ||
cb.errorsBuffer.Do(func(x interface{}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will output the current error and then the rest.
errors ordered as 1 2 3
will be output as 3 1 2
circuitbreaker.go
Outdated
func (cb *Breaker) Errors() (errors []error) { | ||
cb.errorsBuffer.Do(func(x interface{}) { | ||
if x != nil { | ||
errors = append(errors, x.(error)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might as well pre-allocate slice since you know the max number of elements
can allocate n + 1 and then move the first element to the end to get the correct ordering
circuitbreaker.go
Outdated
@@ -302,7 +338,7 @@ func (cb *Breaker) Success() { | |||
cb.backoffLock.Unlock() | |||
|
|||
state := cb.state() | |||
if state == halfopen { | |||
if state == halfopen || state == open { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add comment why this is needed?
circuitbreaker_test.go
Outdated
if errs[1].Error() != "circuit error" { | ||
t.Fatalf("expected `%s` error, got %s", "circuit error", errs[0].Error()) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add test with empty error buffer
…unreliable timeout test
Add test for race? |
@rubyist can this be merged? |
…unreliable timeout test
Fixes #45