fix_: last command of circuit breaker should always run
When added more command to the circuit breaker, we forget to keep a real fallback mechanism, the last call should ALWAYS be made. As such, i am manually skipping to use circuit breaker in that case.
This commit is contained in:
parent
479eb71372
commit
7c9de0429e
|
@ -92,11 +92,20 @@ func (cb *CircuitBreaker) Execute(cmd *Command) CommandResult {
|
|||
ctx = context.Background()
|
||||
}
|
||||
|
||||
for _, f := range cmd.functors {
|
||||
for i, f := range cmd.functors {
|
||||
if cmd.cancel {
|
||||
break
|
||||
}
|
||||
|
||||
var err error
|
||||
// if last command, execute without circuit
|
||||
if i == len(cmd.functors)-1 {
|
||||
res, execErr := f.exec()
|
||||
err = execErr
|
||||
if err == nil {
|
||||
result = CommandResult{res: res}
|
||||
}
|
||||
} else {
|
||||
circuitName := f.circuitName
|
||||
if cb.circuitNameHandler != nil {
|
||||
circuitName = cb.circuitNameHandler(circuitName)
|
||||
|
@ -112,7 +121,7 @@ func (cb *CircuitBreaker) Execute(cmd *Command) CommandResult {
|
|||
})
|
||||
}
|
||||
|
||||
err := hystrix.DoC(ctx, circuitName, func(ctx context.Context) error {
|
||||
err = hystrix.DoC(ctx, circuitName, func(ctx context.Context) error {
|
||||
res, err := f.exec()
|
||||
// Write to result only if success
|
||||
if err == nil {
|
||||
|
@ -120,7 +129,7 @@ func (cb *CircuitBreaker) Execute(cmd *Command) CommandResult {
|
|||
}
|
||||
return err
|
||||
}, nil)
|
||||
|
||||
}
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
|
@ -134,7 +143,6 @@ func (cb *CircuitBreaker) Execute(cmd *Command) CommandResult {
|
|||
// Lets abuse every provider with the same amount of MaxConcurrentRequests,
|
||||
// keep iterating even in case of ErrMaxConcurrency error
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue