Documentation
¶
Overview ¶
The retry package encapsulates the mechanism around retrying operation.
It is a golang implementation for nodejs: https://www.npmjs.com/package/retry.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Operation ¶
type Operation struct {
Retries int // The maximum amount of times to retry the operation
MinInteval time.Duration // default is 1s
MaxInteval time.Duration // defaults is equals to MinInteval
Factor float64 // The exponential factor to use, default is 1
Randomize bool // Randomizes the timeouts by multiplying with a factor between 0.5 to 1.5
}
Operation defines the options for retry sleepInteval = min(random * minInteval * pow(factor, attempt), maxInteval)
func (*Operation) Attempt ¶
Attampt accepts the function fn that is to be retried and executes it.
Example ¶
package main
import (
"fmt"
"time"
"github.com/subchen/go-stack/retry"
)
func main() {
operation := &retry.Operation{
Retries: 3,
MinInteval: 1 * time.Second,
Factor: 1.2,
Randomize: true,
}
err := operation.Attempt(func(attempt int) error {
fmt.Printf("%v: %d: do something\n", time.Now(), attempt)
return fmt.Errorf("some error")
})
if err != nil {
panic(err)
}
}
Click to show internal directories.
Click to hide internal directories.