@@ -3,6 +3,7 @@ package client
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "time"
6
7
7
8
"github.com/harness/harness-mcp/client/dto"
8
9
)
@@ -52,10 +53,39 @@ func (l *LogService) DownloadLogs(ctx context.Context, scope dto.Scope, planExec
52
53
// Initialize the response object
53
54
response := & dto.LogDownloadResponse {}
54
55
55
- // Make the POST request
56
- err = l .Client .Post (ctx , logDownloadPath , params , nil , response )
57
- if err != nil {
58
- return "" , fmt .Errorf ("failed to fetch log download URL: %w" , err )
56
+ // Make the POST request with retry logic
57
+ maxAttempts := 3
58
+ timeBetweenAttempts := 3 * time .Second
59
+ successObtained := false
60
+ var lastErr error
61
+
62
+ for attempt := 1 ; attempt <= maxAttempts ; attempt ++ {
63
+ response = & dto.LogDownloadResponse {}
64
+ err = l .Client .Post (ctx , logDownloadPath , params , nil , response )
65
+ if err != nil {
66
+ lastErr = fmt .Errorf ("failed to fetch log download URL (attempt %d): %w" , attempt , err )
67
+ if attempt == maxAttempts {
68
+ break
69
+ }
70
+ time .Sleep (timeBetweenAttempts )
71
+ continue
72
+ }
73
+
74
+ if response .Status == "success" {
75
+ successObtained = true
76
+ break
77
+ }
78
+
79
+ if attempt == maxAttempts {
80
+ lastErr = fmt .Errorf ("status did not become success after %d attempts, last status: %s" , maxAttempts , response .Status )
81
+ break
82
+ }
83
+
84
+ time .Sleep (timeBetweenAttempts )
85
+ }
86
+
87
+ if ! successObtained {
88
+ return "" , lastErr
59
89
}
60
90
61
91
return response .Link , nil
0 commit comments