Feature Description
Add a reusable retry utility/package that retries a given function as long as it returns an error.
The package should provide sensible defaults (e.g. max attempts, per-attempt timeout) while allowing customization.
The retried function should follow a simple and common signature:
func(ctx context.Context) error
This keeps the API ergonomic and easy to integrate across the codebase.
Use Case
Many operations (network calls, external services, transient I/O, etc.) can fail temporarily and benefit from retry logic.
Currently, retry behavior is often reimplemented ad hoc, leading to duplicated logic and inconsistent behavior.
A shared retry package would:
- Reduce boilerplate
- Centralize retry behavior and defaults
- Improve reliability for transient failures
- Encourage consistent patterns across services
Proposed Solution
Introduce a retry package that:
-
Retries execution while the function returns an error
-
Supports configurable options such as:
- Maximum retry attempts (default: 3)
- Per-attempt timeout
- Optional backoff strategy
-
Uses context.Context for cancellation and deadlines
-
Stops retrying when:
- The function succeeds
- The max attempt limit is reached
- The context is canceled or times out
Additional Context
This utility is intended to be lightweight, dependency-free (if possible), and broadly applicable across internal packages.
Pseudo Code
err := retry.Do(ctx, retry.Options{
MaxAttempts: 3,
Timeout: time.Second,
}, func(ctx context.Context) error {
return callExternalService(ctx)
})
Feature Description
Add a reusable retry utility/package that retries a given function as long as it returns an error.
The package should provide sensible defaults (e.g. max attempts, per-attempt timeout) while allowing customization.
The retried function should follow a simple and common signature:
This keeps the API ergonomic and easy to integrate across the codebase.
Use Case
Many operations (network calls, external services, transient I/O, etc.) can fail temporarily and benefit from retry logic.
Currently, retry behavior is often reimplemented ad hoc, leading to duplicated logic and inconsistent behavior.
A shared retry package would:
Proposed Solution
Introduce a retry package that:
Retries execution while the function returns an error
Supports configurable options such as:
Uses
context.Contextfor cancellation and deadlinesStops retrying when:
Additional Context
This utility is intended to be lightweight, dependency-free (if possible), and broadly applicable across internal packages.
Pseudo Code