* modify * update * add acl * add feature * update dockerfile * add deploy * update * update * plugins * plugins * update * update * update * fixed * remove * fixed * add log * update * fixed * update * fix config * add http api * add http api * resp * add config for work chan * update * fixed * update * disable trace * fixed * change acl * fixed * fixed res * dd * dd * ddd * dd * update * fixed * update * add * fixed * update key * add log * update * format * update * update auth * update * update readme * added * update * fixed * fixed * fix * upade * update * update
35 lines
1.0 KiB
Markdown
35 lines
1.0 KiB
Markdown
circuit-breaker
|
|
===============
|
|
|
|
[](https://travis-ci.org/eapache/go-resiliency)
|
|
[](https://godoc.org/github.com/eapache/go-resiliency/breaker)
|
|
[](https://eapache.github.io/conduct.html)
|
|
|
|
The circuit-breaker resiliency pattern for golang.
|
|
|
|
Creating a breaker takes three parameters:
|
|
- error threshold (for opening the breaker)
|
|
- success threshold (for closing the breaker)
|
|
- timeout (how long to keep the breaker open)
|
|
|
|
```go
|
|
b := breaker.New(3, 1, 5*time.Second)
|
|
|
|
for {
|
|
result := b.Run(func() error {
|
|
// communicate with some external service and
|
|
// return an error if the communication failed
|
|
return nil
|
|
})
|
|
|
|
switch result {
|
|
case nil:
|
|
// success!
|
|
case breaker.ErrBreakerOpen:
|
|
// our function wasn't run because the breaker was open
|
|
default:
|
|
// some other error
|
|
}
|
|
}
|
|
```
|