Skip to content

Commit d4f5a4e

Browse files
committed
feat: implement runWithRetry function for command execution with retry logic
1 parent e6ac581 commit d4f5a4e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

cli/magefile.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ func SyncSkills() error {
281281
{"git", "-C", tempDir, "sparse-checkout", "set", skillsSourcePath},
282282
}
283283
for _, args := range cmds {
284-
if err := sh.RunV(args[0], args[1:]...); err != nil {
284+
if err := runWithRetry(args[0], args[1:]...); err != nil {
285285
return fmt.Errorf("git command failed: %w", err)
286286
}
287287
}
@@ -378,6 +378,23 @@ func SyncSkills() error {
378378
return UpdateCounts()
379379
}
380380

381+
// runWithRetry runs a command with up to 3 retries on failure.
382+
func runWithRetry(cmd string, args ...string) error {
383+
const maxRetries = 3
384+
var err error
385+
for i := 0; i < maxRetries; i++ {
386+
if i > 0 {
387+
delay := time.Duration(i*5) * time.Second
388+
fmt.Printf(" ⚠️ Attempt %d/%d failed, retrying in %s...\n", i, maxRetries, delay)
389+
time.Sleep(delay)
390+
}
391+
if err = sh.RunV(cmd, args...); err == nil {
392+
return nil
393+
}
394+
}
395+
return err
396+
}
397+
381398
// mergeSkillDir merges an upstream skill directory into a local one.
382399
// Files modified locally are preserved; new/unchanged upstream files are copied.
383400
func mergeSkillDir(src, dst string) (added, updated, kept int, err error) {

0 commit comments

Comments
 (0)