• This repository has been archived on 05/Apr/2019
  • Stars
    star
    123
  • Rank 281,127 (Top 6 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 8 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Retryable errors in Golang

Retro - Retryable errors in Golang

⚠️ Note: This library is no longer maintained ⚠️

Codeship Status for codeship/go-retro

Retry allows you to wrap failure prone sections of code in retry blocks, and conditionally retry different types of errors. To retry an error within a block, simply return a custom error type matching the provided interface. By default, wrapping code in a retro block will have no effect.

Usage

// Wrap your code block with retro
finalErr := retro.DoWithRetry(func() error{
    // Hit an external API
    return DoMyFunc(args)
})

Any errors matching the RetryableError interface bubbled up will automatically retry the code block.

For more detailed examples see the examples folder.

Independent sections of code within a chain can be wrapped conditionally in retro blocks as needed. You should always try and keep retry blocks as small as possible to reduce code and requests being re-run.

Retrying

You can use two types of provided error retry patterns, or create your own:

Static retryable errors

These errors retry X times every Y seconds. To create a static retryable error use retro.NewStaticRetryableError(err error, maxAttempts, waitSeconds int). For generic errors you can reference a shared variable, for dynamic errors you can create an error with the relevant base error message each time. Error retrying state is stored in the retro loop, not the RetryableError.

Backoff retryable errors

These errors use quadrilateral equation based on Sidekiq retries to increasingly space out subsequent attempts. To create a backoff retryable error use retro.NewBackoffRetryableError(err error, maxAttempts int). For generic errors you can reference a shared variable, for dynamic errors you can create an error with the relevant base error message each time. Error retrying state is stored in the retro loop, not the RetryableError.

Retry attempts

The retro retry loop will keep track of how many times it has looped. Any time it gets an error it compares the state against the allowed retry conditions for the latest error. This means that should the loop initially retry with an error allowing ten retries, if the second error indicates only two retries or fewer are allowed, then the loop will no longer retry since it has already retried twice.

More Repositories

1

go-best-practices

Codeship Golang Best Practices
Makefile
744
star
2

scripts

Scripts for use on Codeship Basic
Shell
217
star
3

modelist

Flexible & Customizable Modelstructure for awesome data management.
JavaScript
68
star
4

dns_deploy

Continuous Deployment for your DNS Records
Ruby
51
star
5

codeship-tool-examples

Examples to get you started using Codeship Pro. Download the local CLI to follow along with these examples locally.
Shell
51
star
6

codeship-pro-tutorial

A simple introductory tutorial for the Codeship Docker Infrastructure
Ruby
21
star
7

RIG

An aesthetically unopinionated CSS Framework by Codeship.
CSS
20
star
8

codeship-go

Go library for accessing the Codeship API v2
Go
18
star
9

shipyard

A lightweight, CSS framework for Rails & Jekyll applications
Sass
15
star
10

dns-example

How to use dnsdeploy with Codeship
Ruby
14
star
11

ci-guide

Ruby
13
star
12

codeship-ruby

[deprecated] Easily interact with Codeship
Ruby
13
star
13

storybook-surge-github-action

Build and deploy your storybook.js to branch specific Surge.sh sites
Shell
12
star
14

jest-acceptance

Snapshot driven acceptance testing with jest
TypeScript
10
star
15

go-hello-world

**Docker 17.05** A simple hello-world application written in Go to illustrate multi-stage builds, and the builder pattern
Go
9
star
16

atom-codeship-status

Display your Codeship status in the Atom status bar!
CoffeeScript
7
star
17

image-size-webinar

4
star
18

screencast-storyboards

The storyboards for screecasts about how to set up the Codeship with various technologies.
Ruby
2
star
19

node-test-app

JavaScript
1
star
20

metriks-sidekiq

Ruby
1
star
21

ci-workflow-demo

CSS
1
star
22

codeship-tool-example-lb

Just example 18: LB as its own project
Go
1
star