Skip to content

Commit

Permalink
chore(*): -
Browse files Browse the repository at this point in the history
  • Loading branch information
enenumxela committed Oct 5, 2024
1 parent 8c433a7 commit b386379
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 112 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 🚨 CodeQL Analysis
name: 🚨 Analyze Code (CodeQL)

on:
push:
Expand All @@ -17,7 +17,7 @@ on:

jobs:
analyze:
name: Analyze
name: Analyze Code (CodeQL)
strategy:
fail-fast: false
matrix:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 💅 Lint Test
name: 💅🏻 Lint

on:
push:
Expand All @@ -20,7 +20,7 @@ permissions:

jobs:
lint:
name: Lint Test
name: Lint
runs-on: ubuntu-latest
steps:
-
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 🧪 Testing
name: 🧪 Test

on:
push:
Expand All @@ -16,7 +16,7 @@ on:
workflow_dispatch:

jobs:
build:
test:
name: Test
strategy:
matrix:
Expand Down
5 changes: 5 additions & 0 deletions .vscode/extenstions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"golang.go"
]
}
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ Please review the following guidelines before contributing. Also, feel free to p

## Have a Question?

Please don't open a GitHub issue for questions about how to use `hqgoretry`, as the goal is to use issues for managing bugs and feature requests. Issues that are related to general support will be closed.
Please don't open a GitHub issue for questions about how to use `hq-go-retrier`, as the goal is to use issues for managing bugs and feature requests. Issues that are related to general support will be closed.

## Found a Bug?

If you've identified a bug in `hqgoretry`, please [submit an issue](#create-an-issue) to our GitHub repo: [hueristiq/hqgoretry](https://github.com/hueristiq/hqgoretry/issues/new). Please also feel free to submit a [Pull Request](#pull-requests) with a fix for the bug!
If you've identified a bug in `hq-go-retrier`, please [submit an issue](#create-an-issue) to our GitHub repo: [hueristiq/hq-go-retrier](https://github.com/hueristiq/hq-go-retrier/issues/new). Please also feel free to submit a [Pull Request](#pull-requests) with a fix for the bug!

## Have a Feature Request?

Expand All @@ -31,7 +31,7 @@ Assuming no existing issues exist, please ensure you include required informatio

We may have additional questions and will communicate through the GitHub issue, so please respond back to our questions to help reproduce and resolve the issue as quickly as possible.

New issues can be created with in our [GitHub repo](https://github.com/hueristiq/hqgoretry/issues/new).
New issues can be created with in our [GitHub repo](https://github.com/hueristiq/hq-go-retrier/issues/new).

### Pull Requests

Expand All @@ -49,6 +49,6 @@ When submitting code, please make every effort to follow existing conventions an

### License

By contributing your code, you agree to license your contribution under the terms of the [MIT License](https://github.com/hueristiq/hqgoretry/blob/master/LICENSE).
By contributing your code, you agree to license your contribution under the terms of the [MIT License](https://github.com/hueristiq/hq-go-retrier/blob/master/LICENSE).

All files are released with the MIT license.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
SHELL = /bin/sh

# Define the project name for easy reference.
PROJECT = "hqgoretry"
PROJECT = "hq-go-retrier"

# --- Go(Golang) ------------------------------------------------------------------------------------

Expand Down
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# hqgoretry
# hq-go-retrier

![made with go](https://img.shields.io/badge/made%20with-Go-0000FF.svg) [![license](https://img.shields.io/badge/license-MIT-gray.svg?color=0000FF)](https://github.com/hueristiq/hqgoretry/blob/master/LICENSE) ![maintenance](https://img.shields.io/badge/maintained%3F-yes-0000FF.svg) [![open issues](https://img.shields.io/github/issues-raw/hueristiq/hqgoretry.svg?style=flat&color=0000FF)](https://github.com/hueristiq/hqgoretry/issues?q=is:issue+is:open) [![closed issues](https://img.shields.io/github/issues-closed-raw/hueristiq/hqgoretry.svg?style=flat&color=0000FF)](https://github.com/hueristiq/hqgoretry/issues?q=is:issue+is:closed) [![contribution](https://img.shields.io/badge/contributions-welcome-0000FF.svg)](https://github.com/hueristiq/hqgoretry/blob/master/CONTRIBUTING.md)
![made with go](https://img.shields.io/badge/made%20with-Go-0000FF.svg) [![license](https://img.shields.io/badge/license-MIT-gray.svg?color=0000FF)](https://github.com/hueristiq/hq-go-retrier/blob/master/LICENSE) ![maintenance](https://img.shields.io/badge/maintained%3F-yes-0000FF.svg) [![open issues](https://img.shields.io/github/issues-raw/hueristiq/hq-go-retrier.svg?style=flat&color=0000FF)](https://github.com/hueristiq/hq-go-retrier/issues?q=is:issue+is:open) [![closed issues](https://img.shields.io/github/issues-closed-raw/hueristiq/hq-go-retrier.svg?style=flat&color=0000FF)](https://github.com/hueristiq/hq-go-retrier/issues?q=is:issue+is:closed) [![contribution](https://img.shields.io/badge/contributions-welcome-0000FF.svg)](https://github.com/hueristiq/hq-go-retrier/blob/master/CONTRIBUTING.md)

`hqgoretry` is a lightweight and flexible [Go (Golang)](http://golang.org/) package designed to implement retry mechanisms with customizable backoff strategies. It helps developers manage transient failures efficiently by retrying operations that may fail intermittently.
`hq-go-retrier` is a [Go (Golang)](http://golang.org/) designed to manage retries for operations that might temporarily fail. It allows developers to customize how retries are handled using different strategies, such as increasing the wait time between each attempt - backoffs and jitters.

> [!TIP]
> **Backoff** is a strategy used to manage retry intervals when handling transient failures in a system. Instead of retrying an operation immediately after a failure, the backoff mechanism increases the waiting period between retries, often to prevent overloading the system or further exacerbating the issue.
Expand Down Expand Up @@ -33,14 +33,14 @@
To install the package, run the following command in your terminal:

```bash
go get -v -u github.com/hueristiq/hqgoretry
go get -v -u github.com/hueristiq/hq-go-retrier
```

This command will download and install the `hqgoretry` package into your Go workspace, making it available for use in your projects.
This command will download and install the `hq-go-retrier` package into your Go workspace, making it available for use in your projects.

## Usage

Here's a simple example demonstrating how to use `hqgoretry`:
Here's a simple example demonstrating how to use `hq-go-retrier`:

```go
package main
Expand All @@ -51,8 +51,8 @@ import (
"fmt"
"time"

"github.com/hueristiq/hqgoretry"
"github.com/hueristiq/hqgoretry/backoff"
retrier "github.com/hueristiq/hq-go-retrier"
"github.com/hueristiq/hq-go-retrier/backoff"
)

func main() {
Expand All @@ -66,11 +66,11 @@ func main() {
defer cancel()

// Retry the operation with custom configuration
err := hqgoretry.Retry(ctx, operation,
hqgoretry.WithMaxRetries(5),
hqgoretry.WithMinDelay(100*time.Millisecond),
hqgoretry.WithMaxDelay(1*time.Second),
hqgoretry.WithBackoff(backoff.ExponentialWithDecorrelatedJitter()),
err := retrier.Retry(ctx, operation,
retrier.WithMaxRetries(5),
retrier.WithMinDelay(100*time.Millisecond),
retrier.WithMaxDelay(1*time.Second),
retrier.WithBackoff(backoff.ExponentialWithDecorrelatedJitter()),
)

if err != nil {
Expand All @@ -92,19 +92,19 @@ The following options can be used to customize the retry behavior:

## Contributing

We welcome contributions! Feel free to submit [Pull Requests](https://github.com/hueristiq/hqgoretry/pulls) or report [Issues](https://github.com/hueristiq/hqgoretry/issues). For more details, check out the [contribution guidelines](https://github.com/hueristiq/hqgoretry/blob/master/CONTRIBUTING.md).
We welcome contributions! Feel free to submit [Pull Requests](https://github.com/hueristiq/hq-go-retrier/pulls) or report [Issues](https://github.com/hueristiq/hq-go-retrier/issues). For more details, check out the [contribution guidelines](https://github.com/hueristiq/hq-go-retrier/blob/master/CONTRIBUTING.md).

## Licensing

This package is licensed under the [MIT license](https://opensource.org/license/mit). You are free to use, modify, and distribute it, as long as you follow the terms of the license. You can find the full license text in the repository - [Full MIT license text](https://github.com/hueristiq/hqgoretry/blob/master/LICENSE).
This package is licensed under the [MIT license](https://opensource.org/license/mit). You are free to use, modify, and distribute it, as long as you follow the terms of the license. You can find the full license text in the repository - [Full MIT license text](https://github.com/hueristiq/hq-go-retrier/blob/master/LICENSE).

## Credits

### Contributors

A huge thanks to all the contributors who have helped make `hqgoretry` what it is today!
A huge thanks to all the contributors who have helped make `hq-go-retrier` what it is today!

[![contributors](https://contrib.rocks/image?repo=hueristiq/hqgoretry&max=500)](https://github.com/hueristiq/hqgoretry/graphs/contributors)
[![contributors](https://contrib.rocks/image?repo=hueristiq/hq-go-retrier&max=500)](https://github.com/hueristiq/hq-go-retrier/graphs/contributors)

### Similar Projects

Expand Down
2 changes: 1 addition & 1 deletion backoff/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"sync"
"time"

"github.com/hueristiq/hqgoretry/jitter"
"github.com/hueristiq/hq-go-retrier/jitter"
)

// Backoff is a function type that calculates the delay between retry attempts.
Expand Down
2 changes: 1 addition & 1 deletion backoff/backoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/hueristiq/hqgoretry/backoff"
"github.com/hueristiq/hq-go-retrier/backoff"
"github.com/stretchr/testify/assert"
)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/hueristiq/hqgoretry
module github.com/hueristiq/hq-go-retrier

go 1.23.1

Expand Down
2 changes: 1 addition & 1 deletion jitter/jitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/hueristiq/hqgoretry/jitter"
"github.com/hueristiq/hq-go-retrier/jitter"
"github.com/stretchr/testify/assert"
)

Expand Down
40 changes: 40 additions & 0 deletions retrier.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package retrier

import (
"time"

"github.com/hueristiq/hq-go-retrier/backoff"
)

type Configuration struct {
maxRetries int
minDelay time.Duration
maxDelay time.Duration
backoff backoff.Backoff
}

type Option func(*Configuration)

func WithMaxRetries(retries int) Option {
return func(c *Configuration) {
c.maxRetries = retries
}
}

func WithMaxDelay(delay time.Duration) Option {
return func(c *Configuration) {
c.maxDelay = delay
}
}

func WithMinDelay(delay time.Duration) Option {
return func(c *Configuration) {
c.minDelay = delay
}
}

func WithBackoff(strategy backoff.Backoff) Option {
return func(c *Configuration) {
c.backoff = strategy
}
}
43 changes: 6 additions & 37 deletions hqgoretry.go → retry.go
Original file line number Diff line number Diff line change
@@ -1,54 +1,23 @@
package hqgoretry
package retrier

import (
"context"
"time"

"github.com/hueristiq/hqgoretry/backoff"
"github.com/hueristiq/hq-go-retrier/backoff"
)

type Operation func() (err error)

func (o Operation) withEmptyData() OperationWithData[struct{}] {
return func() (struct{}, error) {
func (o Operation) withEmptyData() (operationWithData OperationWithData[struct{}]) {
operationWithData = func() (struct{}, error) {
return struct{}{}, o()
}
}

type OperationWithData[T any] func() (data T, err error)

type Configuration struct {
maxRetries int
minDelay time.Duration
maxDelay time.Duration
backoff backoff.Backoff
}

type Option func(*Configuration)

func WithMaxRetries(retries int) Option {
return func(c *Configuration) {
c.maxRetries = retries
}
}

func WithMaxDelay(delay time.Duration) Option {
return func(c *Configuration) {
c.maxDelay = delay
}
}

func WithMinDelay(delay time.Duration) Option {
return func(c *Configuration) {
c.minDelay = delay
}
return
}

func WithBackoff(strategy backoff.Backoff) Option {
return func(c *Configuration) {
c.backoff = strategy
}
}
type OperationWithData[T any] func() (data T, err error)

func Retry(ctx context.Context, operation Operation, opts ...Option) (err error) {
_, err = RetryWithData(ctx, operation.withEmptyData(), opts...)
Expand Down
Loading

0 comments on commit b386379

Please sign in to comment.