Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: merge palette-api-go into palette-sdk-go #123

Merged
merged 5 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Editor and IDE paraphernalia
.idea
.vscode
go.work.sum

# Directories
bin
api/hapi

# Lint/test output
golangci-report.xml
Expand Down
2 changes: 2 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ issues:
# don't skip warning about doc comments
# don't exclude the default set of lint
exclude-use-default: false
exclude-dirs:
- "api/apiutil"
exclude-files:
- ".*_test\\.go"

Expand Down
4 changes: 0 additions & 4 deletions CHANGELOG

This file was deleted.

1 change: 0 additions & 1 deletion OWNERS_ALIAS
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
aliases:
palette-sdk-go-dev:
- nikchern
- tylergillson
8 changes: 8 additions & 0 deletions api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Palette API - client & models

A swagger client and models for Palette.

## Update client & models
```
./generate.sh ./
```
53 changes: 53 additions & 0 deletions api/apiutil/retry/retry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package retry

import (
"fmt"
"math/rand"
"time"
)

type RetryOption struct {
retryMsg string
attempts int
sleep time.Duration
retryFlag bool
}

func NewRetryOption(retryMsg string, attempts int, sleep time.Duration, retryFlag bool) *RetryOption {
return &RetryOption{retryMsg: retryMsg, attempts: attempts, sleep: sleep, retryFlag: retryFlag}
}

func (retryOption *RetryOption) Retry(f func() error) error {
return retryOp(retryOption.retryMsg, retryOption.attempts, retryOption.sleep, f, retryOption.retryFlag)
}

func Retry(retryMsg string, attempts int, sleep time.Duration, f func() error) error {
return retryOp(retryMsg, attempts, sleep, f, true)
}

func RetryWithErrRetryCond(retryMsg string, attempts int, sleep time.Duration, f func() error) error {
return retryOp(retryMsg, attempts, sleep, f, false)
}

func retryOp(retryMsg string, attempts int, sleep time.Duration, f func() error, retryFlag bool) error {

rand.Seed(time.Now().UnixNano())
var err error
t := attempts
for ; attempts >= 0; attempts-- {
if t > attempts {
fmt.Printf("retrying (%d/%d): %s ", t-attempts, t, retryMsg)
}
err = f()
if err != nil {
if sleep > 0 {
time.Sleep(sleep)
jitter := time.Duration(rand.Int63n(int64(sleep)))
sleep = (2 * sleep) + jitter/2 //exponential sleep with jitter
}
} else {
return nil
}
}
return err
}
Loading
Loading