Skip to content

Latest commit

 

History

History
43 lines (36 loc) · 1.25 KB

README.md

File metadata and controls

43 lines (36 loc) · 1.25 KB

Retry is a pretty simple library to ensure your work to be done

godoc

Go Report Card cover.run

Features

  • Retry to run a workflow(Ex. rpc or db access)
  • Customize backoff strategy
  • Retry accoding to your type of error

Examples

func ExampleEnsure() {
    r := New()
    ctx, cancel := context.WithTimeout(context.Background(), time.Second)
    defer cancel()

    err := r.Ensure(ctx, func() error {
        resp, err := http.Get("https://www.example.com")
        // Get error can be retried
        if err != nil {
            log.Println(err)
            return Retriable(err)
        }
        log.Println(resp)

        buf := bytes.NewBuffer(nil)
        resp, err = http.Post("https://example.com/upload", "image/jpeg", buf)
        // Post error should not be retried
        if err != nil {
            return err
        }
        log.Println(resp)
        return nil
    })
    if err != nil {
        log.Fatal(err)
    }
}