fichier: implement custom pacer to deal with the new rate limiting

This commit is contained in:
buengese 2020-04-24 03:15:52 +02:00 committed by buengese
parent 8bf6ab2c52
commit 7f776c64f0
2 changed files with 8 additions and 6 deletions

View File

@ -17,6 +17,7 @@ import (
// retryErrorCodes is a slice of error codes that we will retry // retryErrorCodes is a slice of error codes that we will retry
var retryErrorCodes = []int{ var retryErrorCodes = []int{
429, // Too Many Requests. 429, // Too Many Requests.
403, // Forbidden (may happen when request limit is exceeded)
500, // Internal Server Error 500, // Internal Server Error
502, // Bad Gateway 502, // Bad Gateway
503, // Service Unavailable 503, // Service Unavailable

View File

@ -25,9 +25,10 @@ import (
const ( const (
rootID = "0" rootID = "0"
apiBaseURL = "https://api.1fichier.com/v1" apiBaseURL = "https://api.1fichier.com/v1"
minSleep = 334 * time.Millisecond // 3 API calls per second is recommended minSleep = 400 * time.Millisecond // api is extremely rate limited now
maxSleep = 5 * time.Second maxSleep = 5 * time.Second
decayConstant = 2 // bigger for slower decay, exponential decayConstant = 2 // bigger for slower decay, exponential
attackConstant = 0 // start with max sleep
) )
func init() { func init() {
@ -185,7 +186,7 @@ func NewFs(name string, root string, config configmap.Mapper) (fs.Fs, error) {
name: name, name: name,
root: root, root: root,
opt: *opt, opt: *opt,
pacer: fs.NewPacer(pacer.NewDefault(pacer.MinSleep(minSleep), pacer.MaxSleep(maxSleep), pacer.DecayConstant(decayConstant))), pacer: fs.NewPacer(pacer.NewDefault(pacer.MinSleep(minSleep), pacer.MaxSleep(maxSleep), pacer.DecayConstant(decayConstant), pacer.AttackConstant(attackConstant))),
baseClient: &http.Client{}, baseClient: &http.Client{},
} }