Skip to content

Commit

Permalink
refactor: merge palette-api-go into palette-sdk-go (#123)
Browse files Browse the repository at this point in the history
* chore: merge palette-api-go into sdk
---------

Signed-off-by: Tyler Gillson <[email protected]>
  • Loading branch information
TylerGillson authored Aug 7, 2024
1 parent 028c11d commit 4ded994
Show file tree
Hide file tree
Showing 3,828 changed files with 554,006 additions and 994 deletions.
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

0 comments on commit 4ded994

Please sign in to comment.