MCPcopy Index your code
hub / github.com/rclone/rclone / Run

Function Run

cmd/cmd.go:240–340  ·  view source on GitHub ↗

Run the function with stats and retries if required

(Retry bool, showStats bool, cmd *cobra.Command, f func() error)

Source from the content-addressed store, hash-verified

238
239// Run the function with stats and retries if required
240func Run(Retry bool, showStats bool, cmd *cobra.Command, f func() error) {
241 ctx := context.Background()
242 ci := fs.GetConfig(ctx)
243 var cmdErr error
244 stopStats := func() {}
245 if !showStats && ShowStats() {
246 showStats = true
247 }
248 if ci.Progress {
249 stopStats = startProgress()
250 } else if showStats {
251 stopStats = StartStats()
252 }
253 SigInfoHandler()
254 for try := 1; try <= ci.Retries; try++ {
255 cmdErr = f()
256 cmdErr = fs.CountError(ctx, cmdErr)
257 lastErr := accounting.GlobalStats().GetLastError()
258 if cmdErr == nil {
259 cmdErr = lastErr
260 }
261 if !Retry || !accounting.GlobalStats().Errored() {
262 if try > 1 {
263 fs.Errorf(nil, "Attempt %d/%d succeeded", try, ci.Retries)
264 }
265 break
266 }
267 if accounting.GlobalStats().HadFatalError() {
268 fs.Errorf(nil, "Fatal error received - not attempting retries")
269 break
270 }
271 if accounting.GlobalStats().Errored() && !accounting.GlobalStats().HadRetryError() {
272 fs.Errorf(nil, "Can't retry any of the errors - not attempting retries")
273 break
274 }
275 if retryAfter := accounting.GlobalStats().RetryAfter(); !retryAfter.IsZero() {
276 d := time.Until(retryAfter)
277 if d > 0 {
278 fs.Logf(nil, "Received retry after error - sleeping until %s (%v)", retryAfter.Format(time.RFC3339Nano), d)
279 time.Sleep(d)
280 }
281 }
282 if lastErr != nil {
283 fs.Errorf(nil, "Attempt %d/%d failed with %d errors and: %v", try, ci.Retries, accounting.GlobalStats().GetErrors(), lastErr)
284 } else {
285 fs.Errorf(nil, "Attempt %d/%d failed with %d errors", try, ci.Retries, accounting.GlobalStats().GetErrors())
286 }
287 if try < ci.Retries {
288 accounting.GlobalStats().ResetErrors()
289 }
290 if ci.RetriesInterval > 0 {
291 time.Sleep(time.Duration(ci.RetriesInterval))
292 }
293 }
294 stopStats()
295 if showStats && (accounting.GlobalStats().Errored() || *statsInterval > 0) {
296 accounting.GlobalStats().Log()
297 }

Callers 15

lsl.goFile · 0.92
link.goFile · 0.92
rcat.goFile · 0.92
cryptdecode.goFile · 0.92
rmdir.goFile · 0.92
convmv.goFile · 0.92
deletefile.goFile · 0.92
lsd.goFile · 0.92
copy.goFile · 0.92
ls.goFile · 0.92
dlna.goFile · 0.92
http.goFile · 0.92

Calls 15

GetConfigFunction · 0.92
GlobalStatsFunction · 0.92
ErrorfFunction · 0.92
LogfFunction · 0.92
DebugfFunction · 0.92
WriteTerminalTitleFunction · 0.92
ClearFunction · 0.92
ShowStatsFunction · 0.85
startProgressFunction · 0.85
StartStatsFunction · 0.85
resolveExitCodeFunction · 0.85
GetLastErrorMethod · 0.80

Tested by

no test coverage detected