Skip to content

Commit

Permalink
retry on API rate-limit
Browse files Browse the repository at this point in the history
  • Loading branch information
yuval-cloudinary committed Oct 10, 2024
1 parent b3b0809 commit 9eb49af
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions backend/cloudinary/cloudinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,16 @@ func shouldRetry(ctx context.Context, resp *http.Response, err error) (bool, err
return false, err
}
if err != nil {
tryAgain := "Try again on "
if idx := strings.Index(err.Error(), tryAgain); idx != -1 {
layout := "2006-01-02 15:04:05 UTC"
dateStr := err.Error()[idx+len(tryAgain) : idx+len(tryAgain)+len(layout)]
timestamp, err2 := time.Parse(layout, dateStr)
if err2 == nil {
return true, fserrors.NewErrorRetryAfter(time.Until(timestamp))
}
}

fs.Debugf(nil, "Retrying API error %v", err)
return true, err
}
Expand Down

0 comments on commit 9eb49af

Please sign in to comment.