snowplow-devops / go-retry

Simple retry functions for Golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Retry functions for Go

Release

Simple retry functions to add exponential backoff to golang apps.

How to use?

import (
	"time"
	"github.com/sirupsen/logrus"

	"github.com/snowplow-devops/go-retry"
)

func main() {
	// Attempt to execute a function 5 times with backoff
	err := retry.Exponential(5, time.Second, "Error Message Prefix", func() error {
		// Run your code here!
	})
	if err != nil {
		logrus.Fatal(err)
	}

	// Attempt to execute a function 5 times with backoff
	res, err := retry.ExponentialWithInterface(5, time.Second, "Error Message Prefix", func() (interface{}, error) {
		// Run your code here!
	})
	if err != nil {
		logrus.Fatal(err)
	}

	// Cast the result back to the expected type
	resCast := res.(ResultType)
}

About

Simple retry functions for Golang


Languages

Language:Go 77.0%Language:Makefile 23.0%