MCPcopy Index your code
hub / github.com/celer-pkg/celer / executeWithRetry

Method executeWithRetry

pkgs/cmd/exec.go:95–122  ·  view source on GitHub ↗

executeWithRetry calls doExecute, retrying up to retryMaxAttempts times on failure.

(output io.Writer)

Source from the content-addressed store, hash-verified

93
94// executeWithRetry calls doExecute, retrying up to retryMaxAttempts times on failure.
95func (e *executor) executeWithRetry(output io.Writer) error {
96 if e.retryMaxAttempts <= 1 {
97 return e.doExecute(output)
98 }
99
100 var lastErr error
101 for attempt := 1; attempt <= e.retryMaxAttempts; attempt++ {
102 if attempt > 1 {
103 // Reset buffer, to make sure the output buffer is clean after new retry.
104 if r, ok := output.(resetable); ok {
105 r.Reset()
106 }
107 }
108 lastErr = e.doExecute(output)
109 if lastErr == nil {
110 return nil
111 }
112
113 color.Printf(color.Warning, "Attempted (%d/%d): %v\n", attempt, e.retryMaxAttempts, lastErr)
114 if attempt < e.retryMaxAttempts {
115 time.Sleep(time.Duration(attempt) * time.Second)
116 }
117 }
118
119 // Show mesage without "[]".
120 e.title = strings.Trim(e.title, "[]")
121 return fmt.Errorf("%s failed after %d attempts -> %w", e.title, e.retryMaxAttempts, lastErr)
122}
123
124// createLogFile creates and initializes a log file with environment variables and command info.
125func (e *executor) createLogFile(cmd *exec.Cmd) (*os.File, error) {

Callers 3

ExecuteOutputMethod · 0.95
ExecuteOutputLiveMethod · 0.95
ExecuteMethod · 0.95

Calls 3

doExecuteMethod · 0.95
PrintfFunction · 0.92
ResetMethod · 0.65

Tested by

no test coverage detected