Skip to content

Commit

Permalink
Added execution retry support
Browse files Browse the repository at this point in the history
  • Loading branch information
roblaszczak committed Apr 11, 2023
1 parent cbe842b commit 243512d
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions trainings/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func (h *Handlers) detachedRun(ctx context.Context, trainingRootFs *afero.BasePa
os.Exit(1)
}

fmt.Println()

promptResult := internal.Prompt(
internal.Actions{
{Shortcut: '\n', Action: "go to the next exercise", ShortcutAliases: []rune{'\r'}},
Expand All @@ -72,10 +74,28 @@ func (h *Handlers) detachedRun(ctx context.Context, trainingRootFs *afero.BasePa
}

func (h *Handlers) interactiveRun(ctx context.Context, trainingRootFs *afero.BasePathFs) error {
retries := 0

for {
successful, err := h.run(ctx, trainingRootFs)
if err != nil && retries < 3 {
retries++
time.Sleep(time.Duration(retries) * time.Millisecond * 50)
logrus.WithError(err).WithField("retry", retries).Info("execution failed, retrying")
continue
}
retries = 0

fmt.Println()

if err != nil {
return err
fmt.Println(color.RedString("Failed to execute solution: %s", err.Error()))

if !internal.ConfirmPromptDefaultYes("run solution again") {
return err
} else {
continue
}
}

if !successful {
Expand Down Expand Up @@ -131,8 +151,6 @@ func (h *Handlers) run(ctx context.Context, trainingRootFs *afero.BasePathFs) (b
return true, err
}

fmt.Println()

return success, err
}

Expand Down

0 comments on commit 243512d

Please sign in to comment.