PORKBUN: increase req interval and retry on 503 (#3228)

Co-authored-by: Tom Limoncelli <tlimoncelli@stackoverflow.com>
This commit is contained in:
imlonghao 2024-12-10 23:09:55 +08:00 committed by GitHub
parent e774e2d08d
commit de6afe2506
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -77,7 +77,7 @@ func (c *porkbunProvider) post(endpoint string, params requestParams) ([]byte, e
// If request sending too fast, the server will fail with the following error: // If request sending too fast, the server will fail with the following error:
// porkbun API error: Create error: We were unable to create the DNS record. // porkbun API error: Create error: We were unable to create the DNS record.
retry: retry:
time.Sleep(500 * time.Millisecond) time.Sleep(time.Second)
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil { if err != nil {
return []byte{}, err return []byte{}, err
@ -85,13 +85,13 @@ retry:
bodyString, _ := io.ReadAll(resp.Body) bodyString, _ := io.ReadAll(resp.Body)
if resp.StatusCode == 202 { if resp.StatusCode == 202 || resp.StatusCode == 503 {
retrycnt += 1 retrycnt += 1
if retrycnt == 5 { if retrycnt == 5 {
return bodyString, fmt.Errorf("rate limiting exceeded") return bodyString, fmt.Errorf("rate limiting exceeded")
} }
printer.Warnf("Rate limiting.. waiting for %d minute(s)\n", retrycnt) printer.Warnf("Rate limiting.. waiting for %d second(s)\n", retrycnt*10)
time.Sleep(time.Minute * time.Duration(retrycnt)) time.Sleep(time.Second * time.Duration(retrycnt*10))
goto retry goto retry
} }