Skip to content

break: retry: simplify API (remove ClassifierFn, change WorkFn)#17

Merged
marco-m-pix4d merged 5 commits intomasterfrom
simplify-retry
Apr 14, 2026
Merged

break: retry: simplify API (remove ClassifierFn, change WorkFn)#17
marco-m-pix4d merged 5 commits intomasterfrom
simplify-retry

Conversation

@marco-m-pix4d
Copy link
Copy Markdown
Contributor

Cogito is using two HTTP APIs: GitHub And Google Chat.
The GitHub API was wrapped with go-kit/retry since a long time ago, while the Google Chat API was wrapped with go-kit/retry only last week in Pix4D/cogito#177.

While working on the wrapping of the Google Chat API, I realized that go-kit/retry was clumsy to use. Thus this PR.

Old API:

func (rtr Retry) Do(
	backoffFn BackoffFunc,
	classifierFn ClassifierFunc,             // <== will be removed
	workFn WorkFunc,
) error

type ClassifierFunc func(err error) Action   // <== will be removed
type WorkFunc func() error                   // <== will change return signature

New API:

func (rtr Retry) Do(
	backoffFn BackoffFunc,
	workFn WorkFunc,
) error

type WorkFunc func() (Action, error)

Realization:

There is no need for function ClassifierFn, since WorkFn has already all the information
and putting the logic to decide the retry closer to the work makes it easier
to understand what is going on.

Cogito is using two HTTP APIs: GitHub And Google Chat.
The GitHub API was wrapped with go-kit/retry since a long time ago, while the Google Chat API was wrapped with go-kit/retry only last week in Pix4D/cogito#177.

While working on the wrapping of the Google Chat API, I realized that go-kit/retry was clumsy to use. Thus this PR.

Old API:

```go
func (rtr Retry) Do(
	backoffFn BackoffFunc,
	classifierFn ClassifierFunc,             // <== will be removed
	workFn WorkFunc,
) error

type ClassifierFunc func(err error) Action   // <== will be removed
type WorkFunc func() error                   // <== will change return signature
```

New API:

```go
func (rtr Retry) Do(
	backoffFn BackoffFunc,
	workFn WorkFunc,
) error

type WorkFunc func() (Action, error)
```

Realization:

There is no need for function `ClassifierFn`, since `WorkFn` has already all the information
and putting the logic to decide the retry closer to the work makes it easier
to understand what is going on.
Same approach as googlechat.DefaultRetry()
@marco-m-pix4d marco-m-pix4d requested a review from a team as a code owner April 14, 2026 09:05
@marco-m-pix4d marco-m-pix4d changed the title break: retry: simplify API by removing ClassifierFn and changing WorkFn break: retry: simplify API (remove ClassifierFn, change WorkFn) Apr 14, 2026
Comment thread retry/retry_example_test.go
@SpectreVert
Copy link
Copy Markdown
Member

We're missing googlechat in contents: https://github.com/Pix4D/go-kit/blob/master/README.md#contents

image

And last thing:

// the [go-kit.retry] package.

This integrates kind of weirdly on pkg.go.dev:
image

@marco-m-pix4d marco-m-pix4d merged commit fd3ba0e into master Apr 14, 2026
1 check passed
@marco-m-pix4d marco-m-pix4d deleted the simplify-retry branch April 14, 2026 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants