make upload and wait times a constant

This commit is contained in:
Shreyas Goenka 2025-03-06 11:36:21 +01:00
parent 0ac9a2aa97
commit 3811d24e58
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
1 changed files with 8 additions and 3 deletions

View File

@ -58,6 +58,11 @@ func (l *logger) setExecutionContext(ec protos.ExecutionContext) {
}
}
const (
uploadTimeout = 3 * time.Second
waitBetweenRetries = 200 * time.Millisecond
)
func Upload(ctx context.Context, cfg *config.Config) error {
l := fromContext(ctx)
if len(l.logs) == 0 {
@ -78,7 +83,7 @@ func Upload(ctx context.Context, cfg *config.Config) error {
return fmt.Errorf("failed to create API client: %w", err)
}
ctx, cancel := context.WithTimeout(ctx, 3*time.Second)
ctx, cancel := context.WithTimeout(ctx, uploadTimeout)
defer cancel()
// Only try uploading logs for a maximum of 3 times.
@ -101,7 +106,7 @@ func Upload(ctx context.Context, cfg *config.Config) error {
// Partial success. Retry.
if err == nil && resp.NumProtoSuccess < int64(len(protoLogs)) {
log.Debugf(ctx, "Attempt %d was a partial success. Number of logs uploaded: %d out of %d\n", i+1, resp.NumProtoSuccess, len(protoLogs))
time.Sleep(200 * time.Millisecond)
time.Sleep(waitBetweenRetries)
continue
}
@ -115,7 +120,7 @@ func Upload(ctx context.Context, cfg *config.Config) error {
var apiErr *apierr.APIError
if errors.As(err, &apiErr) && apiErr.StatusCode >= 500 {
log.Debugf(ctx, "Attempt %d failed due to a server side error. Retrying status code: %d\n", i+1, apiErr.StatusCode)
time.Sleep(200 * time.Millisecond)
time.Sleep(waitBetweenRetries)
continue
}
}