| 1 |
retrier |
| 2 |
======= |
| 3 |
|
| 4 |
[](https://github.com/eapache/go-resiliency/actions/workflows/golang-ci.yml) |
| 5 |
[](https://godoc.org/github.com/eapache/go-resiliency/retrier) |
| 6 |
[](https://eapache.github.io/conduct.html) |
| 7 |
|
| 8 |
The retriable resiliency pattern for golang. |
| 9 |
|
| 10 |
Creating a retrier takes two parameters: |
| 11 |
- the times to back-off between retries (and implicitly the number of times to |
| 12 |
retry) |
| 13 |
- the classifier that determines which errors to retry |
| 14 |
|
| 15 |
```go |
| 16 |
r := retrier.New(retrier.ConstantBackoff(3, 100*time.Millisecond), nil) |
| 17 |
|
| 18 |
err := r.Run(func() error { |
| 19 |
// do some work |
| 20 |
return nil |
| 21 |
}) |
| 22 |
|
| 23 |
if err != nil { |
| 24 |
// handle the case where the work failed three times |
| 25 |
} |
| 26 |
``` |