-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: merge palette-api-go into palette-sdk-go (#123)
* chore: merge palette-api-go into sdk --------- Signed-off-by: Tyler Gillson <[email protected]>
- Loading branch information
1 parent
028c11d
commit 4ded994
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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
aliases: | ||
palette-sdk-go-dev: | ||
- nikchern | ||
- tylergillson |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ./ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.