retrying

package module
v0.0.0-...-fd1a551 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2017 License: MIT Imports: 7 Imported by: 0

README

retrying

Retrying is a golang binding of python retrying library https://github.com/rholder/retrying

Build Status Go Report Card codecov

Installation

$ go get github.com/yumimobi/retrying

Usage

package main

import (
	"fmt"
	"math/rand"
	"time"

	"github.com/yumimobi/retrying"
)

func init() {
	rand.Seed(time.Now().UnixNano())
}

func main() {
	err := retrying.New().
		Stack(2048, true).
		MaxAttemptTimes(5).
		Function(func() error {
			if rand.Int63n(100) > 80 {
				return nil
			}
			return fmt.Errorf("dllm")
		}).
		WaitFixed(time.Second).
		WaitRandom(time.Second, time.Second*3).
		MaxDelay(time.Minute).
		Try()

	fmt.Println(err == nil)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTimeout             = fmt.Errorf("timeout error")
	ErrNoFunctionSpecified = fmt.Errorf("no function is specified")
)

errors

Functions

This section is empty.

Types

type Retryable

type Retryable struct {
	// contains filtered or unexported fields
}

Retryable model consisting of retry options

func New

func New() *Retryable

New create new retry

func (*Retryable) Function

func (r *Retryable) Function(i interface{}) *Retryable

Function set function i should be a function with no output or last output should be an error

func (*Retryable) MaxAttemptTimes

func (r *Retryable) MaxAttemptTimes(n int64) *Retryable

MaxAttemptTimes set max attempt times

func (*Retryable) MaxDelay

func (r *Retryable) MaxDelay(d time.Duration) *Retryable

MaxDelay set max delay duration

func (*Retryable) Stack

func (r *Retryable) Stack(n int, all bool) *Retryable

Stack set stack parameters used in runtime.Stack

func (*Retryable) Try

func (r *Retryable) Try() error

Try call the wrap function with retry options

func (*Retryable) WaitFixed

func (r *Retryable) WaitFixed(d time.Duration) *Retryable

WaitFixed set fixed wait duration

func (*Retryable) WaitRandom

func (r *Retryable) WaitRandom(min, max time.Duration) *Retryable

WaitRandom set min/max random

Jump to

Keyboard shortcuts

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