Skip to content

A pretty simple library to ensure your work to be done

License

Notifications You must be signed in to change notification settings

shafreeck/retry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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("http://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("http://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)
    }
}

About

A pretty simple library to ensure your work to be done

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages