From 87be43d95f14cdd4ceeabcf4646dd640e06fd46a Mon Sep 17 00:00:00 2001 From: David Ramiro Date: Sun, 26 Feb 2023 18:42:55 +0100 Subject: [PATCH] fix: prevent porkbun rate limit --- pkg/porkbun/porkbun.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/porkbun/porkbun.go b/pkg/porkbun/porkbun.go index ab2bcd9..a61b23e 100644 --- a/pkg/porkbun/porkbun.go +++ b/pkg/porkbun/porkbun.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "net/http" + "time" "github.com/davidramiro/frigabun/internal/config" "github.com/davidramiro/frigabun/internal/logger" @@ -53,11 +54,15 @@ func (p *PorkbunDns) AddRecord() *PorkbunUpdateError { queryErr := porkbunRequest.queryRecord(p) + time.Sleep(2 * time.Second) + if queryErr != nil && queryErr.Code == 409 { logger.Log.Info().Msg("record exists, updating") updateErr := porkbunRequest.updateRecord(p) + time.Sleep(2 * time.Second) + if updateErr != nil { logger.Log.Error().Str("err", updateErr.Message).Msg("porkbun rejected updated record") return &PorkbunUpdateError{Code: 400, Message: updateErr.Message} @@ -65,6 +70,9 @@ func (p *PorkbunDns) AddRecord() *PorkbunUpdateError { } else { createErr := porkbunRequest.createRecord(p) + + time.Sleep(2 * time.Second) + if createErr != nil { logger.Log.Error().Str("err", createErr.Message).Msg("porkbun rejected new record") return &PorkbunUpdateError{Code: 400, Message: createErr.Message}