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
90b3d0fdcc
commit
c08d10b8ab
|
@ -92,11 +92,20 @@ func (cb *CircuitBreaker) Execute(cmd *Command) CommandResult {
|
||||||
ctx = context.Background()
|
ctx = context.Background()
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range cmd.functors {
|
for i, f := range cmd.functors {
|
||||||
if cmd.cancel {
|
if cmd.cancel {
|
||||||
break
|
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
|
circuitName := f.circuitName
|
||||||
if cb.circuitNameHandler != nil {
|
if cb.circuitNameHandler != nil {
|
||||||
circuitName = cb.circuitNameHandler(circuitName)
|
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()
|
res, err := f.exec()
|
||||||
// Write to result only if success
|
// Write to result only if success
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -120,7 +129,7 @@ func (cb *CircuitBreaker) Execute(cmd *Command) CommandResult {
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}, nil)
|
}, nil)
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -134,7 +143,6 @@ func (cb *CircuitBreaker) Execute(cmd *Command) CommandResult {
|
||||||
// Lets abuse every provider with the same amount of MaxConcurrentRequests,
|
// Lets abuse every provider with the same amount of MaxConcurrentRequests,
|
||||||
// keep iterating even in case of ErrMaxConcurrency error
|
// keep iterating even in case of ErrMaxConcurrency error
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue