Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vvatanabe/goretryer
Retry exponential backoff algorithm in Go. Generalized HTTP Request retry logic in aws/aws-sdk-go.
https://github.com/vvatanabe/goretryer
exponential-backoff golang retry
Last synced: 24 days ago
JSON representation
Retry exponential backoff algorithm in Go. Generalized HTTP Request retry logic in aws/aws-sdk-go.
- Host: GitHub
- URL: https://github.com/vvatanabe/goretryer
- Owner: vvatanabe
- License: mit
- Created: 2020-01-18T03:29:46.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-26T10:18:02.000Z (almost 5 years ago)
- Last Synced: 2024-05-21T12:38:01.183Z (6 months ago)
- Topics: exponential-backoff, golang, retry
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# goretryer
Retry exponential backoff algorithm in Go. Generalized HTTP Request retry logic in [aws/aws-sdk-go](https://github.com/aws/aws-sdk-go).
## Requires
- Go 1.13+
## Installation
This package can be installed with the go get command:
```
$ go get github.com/vvatanabe/goretryer
```## Usage
### Basically
```go
package mainimport (
"context"
"errors"
"github.com/vvatanabe/goretryer/exponential"
"log"
"time"
)var ErrTemporary = errors.New("temporary")
func main() {
log.SetFlags(log.Lmicroseconds)
retryer := exponential.Retryer{
NumMaxRetries: 5,
MinRetryDelay: 300 * time.Millisecond,
MaxRetryDelay: 300 * time.Second,
}var cnt int
operation := func(ctx context.Context) error {
cnt++
log.Println("cnt", cnt)
return ErrTemporary
}isErrorRetryable := func(err error) bool {
return err == ErrTemporary
}over, err := retryer.Do(context.Background(), operation, isErrorRetryable)
if err != nil {
log.Printf("retry over: %v, error: %v\n", over, err)
}
}
```## Acknowledgments
See [aws-sdk-go/aws/client/default_retryer.go](https://github.com/aws/aws-sdk-go/blob/84fbd57ef75762a07aade079776907d01be3891d/aws/client/default_retryer.go) for great origins.
## Bugs and Feedback
For bugs, questions and discussions please use the Github Issues.