-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/overflow-conversion-utilities' i…
…nto overflow-conversion-utilities
- Loading branch information
Showing
18 changed files
with
281 additions
and
117 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,26 +10,10 @@ jobs: | |
CLAssistant: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions-ecosystem/action-regex-match@v2 | ||
id: sign-or-recheck | ||
- name: Run CLA Check | ||
uses: jfrog/.github/actions/cla@main | ||
with: | ||
text: ${{ github.event.comment.body }} | ||
regex: '\s*(I have read the CLA Document and I hereby sign the CLA)|(recheck)\s*' | ||
|
||
- name: "CLA Assistant" | ||
if: ${{ steps.sign-or-recheck.outputs.match != '' || github.event_name == 'pull_request_target' }} | ||
# Alpha Release | ||
uses: cla-assistant/[email protected] | ||
env: | ||
# Generated and maintained by GitHub | ||
event_comment_body: ${{ github.event.comment.body }} | ||
event_name: ${{ github.event_name }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
# JFrog's organization secret | ||
PERSONAL_ACCESS_TOKEN : ${{ secrets.CLA_SIGN_TOKEN }} | ||
with: | ||
path-to-signatures: 'signed_clas.json' | ||
path-to-document: 'https://jfrog.com/cla/' | ||
remote-organization-name: 'jfrog' | ||
remote-repository-name: 'jfrog-signed-clas' | ||
# branch should not be protected | ||
branch: 'master' | ||
allowlist: bot* | ||
CLA_SIGN_TOKEN: ${{ secrets.CLA_SIGN_TOKEN }} |
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
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
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 |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package retryexecutor | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"github.com/jfrog/gofrog/log" | ||
"time" | ||
) | ||
|
||
type ExecutionHandlerFunc func() (shouldRetry bool, err error) | ||
|
||
type RetryExecutor struct { | ||
// The context | ||
Context context.Context | ||
|
||
// The amount of retries to perform. | ||
MaxRetries int | ||
|
||
// Number of milliseconds to sleep between retries. | ||
RetriesIntervalMilliSecs int | ||
|
||
// Message to display when retrying. | ||
ErrorMessage string | ||
|
||
// Prefix to print at the beginning of each log. | ||
LogMsgPrefix string | ||
|
||
// ExecutionHandler is the operation to run with retries. | ||
ExecutionHandler ExecutionHandlerFunc | ||
} | ||
|
||
func (runner *RetryExecutor) Execute() error { | ||
var err error | ||
var shouldRetry bool | ||
for i := 0; i <= runner.MaxRetries; i++ { | ||
// Run ExecutionHandler | ||
shouldRetry, err = runner.ExecutionHandler() | ||
|
||
// If we should not retry, return. | ||
if !shouldRetry { | ||
return err | ||
} | ||
if cancelledErr := runner.checkCancelled(); cancelledErr != nil { | ||
return cancelledErr | ||
} | ||
|
||
// Print retry log message | ||
runner.LogRetry(i, err) | ||
|
||
// Going to sleep for RetryInterval milliseconds | ||
if runner.RetriesIntervalMilliSecs > 0 && i < runner.MaxRetries { | ||
time.Sleep(time.Millisecond * time.Duration(runner.RetriesIntervalMilliSecs)) | ||
} | ||
} | ||
// If the error is not nil, return it and log the timeout message. Otherwise, generate new error. | ||
if err != nil { | ||
log.Info(runner.getTimeoutErrorMsg()) | ||
return err | ||
} | ||
return TimeoutError{runner.getTimeoutErrorMsg()} | ||
} | ||
|
||
// Error of this type will be returned if the executor reaches timeout and no other error is returned by the execution handler. | ||
type TimeoutError struct { | ||
errMsg string | ||
} | ||
|
||
func (retryErr TimeoutError) Error() string { | ||
return retryErr.errMsg | ||
} | ||
|
||
func (runner *RetryExecutor) getTimeoutErrorMsg() string { | ||
prefix := "" | ||
if runner.LogMsgPrefix != "" { | ||
prefix = runner.LogMsgPrefix + " " | ||
} | ||
return fmt.Sprintf("%sexecutor timeout after %v attempts with %v milliseconds wait intervals", prefix, runner.MaxRetries, runner.RetriesIntervalMilliSecs) | ||
} | ||
|
||
func (runner *RetryExecutor) LogRetry(attemptNumber int, err error) { | ||
message := fmt.Sprintf("%s(Attempt %v)", runner.LogMsgPrefix, attemptNumber+1) | ||
if runner.ErrorMessage != "" { | ||
message = fmt.Sprintf("%s - %s", message, runner.ErrorMessage) | ||
} | ||
if err != nil { | ||
message = fmt.Sprintf("%s: %s", message, err.Error()) | ||
} | ||
|
||
if err != nil || runner.ErrorMessage != "" { | ||
log.Warn(message) | ||
} else { | ||
log.Debug(message) | ||
} | ||
} | ||
|
||
func (runner *RetryExecutor) checkCancelled() error { | ||
if runner.Context == nil { | ||
return nil | ||
} | ||
contextErr := runner.Context.Err() | ||
if errors.Is(contextErr, context.Canceled) { | ||
log.Info("Retry executor was cancelled") | ||
return contextErr | ||
} | ||
return nil | ||
} |
Oops, something went wrong.