Giter Club home page Giter Club logo

retry's Introduction

♻️ retry Awesome Go

The most advanced interruptible mechanism to perform actions repetitively until successful.

Build Documentation Quality Template Coverage Mirror

💡 Idea

The retry based on Rican7/retry but fully reworked and focused on integration with the 🚧 breaker and the built-in context package.

ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()

action := func(ctx context.Context) (err error) {
	req := req.Clone(ctx)
	resp, err = http.DefaultClient.Do(req)
	return err
}

how := []retry.How{
	strategy.Limit(5),
	strategy.BackoffWithJitter(
		backoff.Fibonacci(10*time.Millisecond),
		jitter.NormalDistribution(
			rand.New(rand.NewSource(time.Now().UnixNano())),
			0.25,
		),
	),
}

if err := retry.Do(ctx, action, how...); err != nil {
	log.Fatal(err)
}

A full description of the idea is available here.

🏆 Motivation

I developed distributed systems at Lazada, and later at Avito, which communicate with each other through a network, and I need a package to make these communications more reliable.

🤼‍♂️ How to

rewriting...

🧩 Integration

The library uses SemVer for versioning, and it is not BC-safe through major releases. You can use go modules to manage its version.

$ go get github.com/kamilsk/retry/v5@latest

🤲 Outcomes

Console tool to execute commands until successful

...

See more details here.

made with ❤️ for everyone

retry's People

Contributors

kamilsk avatar rican7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

retry's Issues

make dev

setup origin and mirror, sync with makefile from semaphore

fix go 1.5 problems

# github.com/kamilsk/retry/classifier
classifier/functional_test.go:43: unknown net.DNSError field 'IsTemporary' in struct literal
ok  	github.com/kamilsk/retry	1.113s
ok  	github.com/kamilsk/retry/backoff	1.010s
FAIL	github.com/kamilsk/retry/classifier [build failed]
?   	github.com/kamilsk/retry/cmd/retry	[no test files]
?   	github.com/kamilsk/retry/cmd/retry/flag	[no test files]
ok  	github.com/kamilsk/retry/jitter	1.015s
ok  	github.com/kamilsk/retry/strategy	1.171s
make: *** [docker-test-1.5] Error 123

integration

  • gitter
  • travis
  • coverall
  • goreport
  • bitbucket

add fix util

$ go get bitbucket.org/kamilsk/retry
package bitbucket.org/kamilsk/retry: code in directory $GOPATH/src/bitbucket.org/kamilsk/retry expects import "github.com/kamilsk/retry"

blocked by #30

provide to brew

  • don't panic
  • continue on error
  • move common parts from go17, pre_go17 to main
  • normal error handling

fix gometalinter

$ make docker-gometalinter
docker run --rm \
	           -v '/Users/kamilsamigullin/Development/go/src/github.com/kamilsk/retrier':'/go/src/github.com/kamilsk/retrier' \
	           -w '/go/src/github.com/kamilsk/retrier' \
	           kamilsk/go-tools:latest \
	           /bin/sh -c 'go list ./... | grep -v /vendor/ | xargs go test -i "$1" && \
	                       gometalinter.v1 --vendor --deadline=20s ./...'
retry.go:1:1:warning: package comment should be of the form "Package retrier ..." (golint)
jitter/jitter_test.go:9::warning: duplicate of jitter_test.go:29-47 (dupl)
jitter/jitter_test.go:29::warning: duplicate of jitter_test.go:9-27 (dupl)
strategy/extended_test.go:24:32:warning: error return value not checked (cannot use nil (untyped nil value) as parameter of type []Strategy) (errcheck)
strategy/extended_test.go:24:32:warning: unused global variable cannot use nil (untyped nil value) as parameter of type []Strategy (varcheck)
example_test.go:21:15:warning: error return value not checked (retrier.Retry(func(attempt uint) error {) (errcheck)
example_test.go:43:15:warning: error return value not checked (logFile.Chdir() // Do something with the file) (errcheck)
example_test.go:83:15:warning: error return value not checked (retrier.Retry() (errcheck)
example_test.go:98:11:warning: error return value not checked (rw.Write([]byte("Internal Server Error"))) (errcheck)
example_test.go:143:11:warning: error return value not checked (rw.Write([]byte("Internal Server Error"))) (errcheck)
make: *** [docker-tool-gometalinter] Error 1

fix gometalinter

  • cmd/retry/flag/flag.go:59:6:warning: type name will be used as flag.FlagSet by other packages, and that stutters; considercalling this Set (golint)
  • cmd/retry/go17_helper.go:54::error: the cancel function returned by context.WithTimeout should be called, not discarded, to avoid a context leak (vet)
  • cmd/retry/go17_helper.go:37:10:warning: error return value not checked (cl.Parse(os.Args[1:])) (errcheck)

prevent output to stderr when context has closed

$ make cmd-test
go install -ldflags "-X 'main.Timeout=100ms'" ./cmd/retry
retry -limit=3 -backoff=lin[10ms] -timeout=500ms -- curl http://unknown.host
error occurred "context deadline exceeded"
curl: (7) Failed to connect to unknown.host port 80: Connection refused

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.