mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-01-12 02:17:43 +08:00
HOSTINGDE: Add simple exponential back-off retry (#1937)
Co-authored-by: Tom Limoncelli <tlimoncelli@stackoverflow.com>
This commit is contained in:
parent
97d9c5889b
commit
83b4a301dc
1 changed files with 18 additions and 4 deletions
|
@ -3,8 +3,10 @@ package hostingde
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/StackExchange/dnscontrol/v3/models"
|
||||
"github.com/StackExchange/dnscontrol/v3/pkg/diff"
|
||||
|
@ -149,16 +151,28 @@ func (hp *hostingdeProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*m
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
corrections := []*models.Correction{
|
||||
corrections = []*models.Correction{
|
||||
{
|
||||
Msg: fmt.Sprintf("\n%s", strings.Join(msg, "\n")),
|
||||
F: func() error {
|
||||
return hp.updateRecords(dc.Name, create, del, mod)
|
||||
for i := 0; i < 10; i++ {
|
||||
err := hp.updateRecords(dc.Name, create, del, mod)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
// Code:10205 indicates the zone is currently blocked due to a running zone update.
|
||||
if !strings.Contains(err.Error(), "Code:10205") {
|
||||
return err
|
||||
}
|
||||
|
||||
// Exponential back-off retry.
|
||||
// Base of 1.8 seemed like a good trade-off, retrying for approximately 45 seconds.
|
||||
time.Sleep(time.Duration(math.Pow(1.8, float64(i))) * 100 * time.Millisecond)
|
||||
}
|
||||
return fmt.Errorf("retry exhaustion: zone blocked for 10 attempts")
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return corrections, nil
|
||||
}
|
||||
|
||||
// Insert Future diff2 version here.
|
||||
|
|
Loading…
Reference in a new issue