Skip to content

Commit b87c12d

Browse files
committed
feat: retry 3 times if unable to find pom data
1 parent bd9da57 commit b87c12d

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

finder/finder.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"log"
77
"sync"
8+
"time"
89

910
"github.com/status-im/go-maven-resolver/fetcher"
1011
"github.com/status-im/go-maven-resolver/pom"
@@ -43,6 +44,10 @@ func (f *Finder) ResolveDep(dep pom.Dependency) (string, *pom.Project, error) {
4344
result := make(chan *fetcher.Result)
4445
defer close(result)
4546

47+
// Add constants for retry logic
48+
const maxRetries = 3
49+
const retryDelay = time.Second * 2
50+
4651
if !dep.HasVersion() {
4752
path := dep.GetMetaPath()
4853
/* We use workers for HTTP request to avoid running out of sockets */
@@ -63,12 +68,24 @@ func (f *Finder) ResolveDep(dep pom.Dependency) (string, *pom.Project, error) {
6368

6469
path := dep.GetPOMPath()
6570
/* We use workers for HTTP request to avoid running out of sockets */
66-
f.fetchers.Queue <- fetcher.NewJob(result, path, repo)
67-
rval = <-result
71+
// Retry logic for fetching data
72+
for attempt := 0; attempt < maxRetries; attempt++ {
73+
f.fetchers.Queue <- fetcher.NewJob(result, path, repo)
74+
rval = <-result
75+
76+
if rval.Data != nil {
77+
break
78+
}
79+
80+
if attempt < maxRetries-1 {
81+
time.Sleep(retryDelay)
82+
}
83+
}
6884

6985
if rval.Data == nil {
7086
return "", nil, errors.New("no pom data")
7187
}
88+
7289
project, err := pom.ProjectFromReader(rval.Data)
7390
if err != nil {
7491
return "", nil, err

0 commit comments

Comments
 (0)