retry

package module
v0.0.0-...-8989bbd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2021 License: Apache-2.0 Imports: 4 Imported by: 1

README

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)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exponential

func Exponential(attempts int, sleep time.Duration, prefix string, f func() error) error

Exponential provides the ability to exponentially retry the execution of a function

func ExponentialWithInterface

func ExponentialWithInterface(attempts int, sleep time.Duration, prefix string, f func() (interface{}, error)) (interface{}, error)

ExponentialWithInterface provides the ability to exponentially retry the execution of a function and return a result from the function

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL