1
0
mirror of https://github.com/gilbertchen/duplicacy synced 2025-12-16 00:03:34 +00:00

Run goimports for the good looks

This commit is contained in:
TheBestPessimist
2017-09-21 08:16:54 +03:00
parent 46917ddf6b
commit ed52850c98

View File

@@ -5,33 +5,34 @@
package duplicacy package duplicacy
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"math/rand" "math/rand"
"net" "net"
"net/http" "net/http"
"net/url" "net/url"
"path" "path"
"strings" "strings"
"sync" "sync"
"time" "time"
"runtime"
"golang.org/x/net/context" "golang.org/x/net/context"
"golang.org/x/oauth2" "golang.org/x/oauth2"
"google.golang.org/api/drive/v3" "google.golang.org/api/drive/v3"
"google.golang.org/api/googleapi" "google.golang.org/api/googleapi"
"runtime"
) )
type GCDStorage struct { type GCDStorage struct {
RateLimitedStorage RateLimitedStorage
service *drive.Service service *drive.Service
idCache map[string]string idCache map[string]string
idCacheLock *sync.Mutex idCacheLock *sync.Mutex
backoffs []float64 backoffs []float64
backoffsRetries []int backoffsRetries []int
isConnected bool isConnected bool
@@ -101,20 +102,20 @@ func (storage *GCDStorage) shouldRetry(threadIndex int, err error) (bool, error)
return false, err return false, err
} }
if storage.backoffs[threadIndex] < LIMIT_BACKOFF_TIME { if storage.backoffs[threadIndex] < LIMIT_BACKOFF_TIME {
storage.backoffs[threadIndex] *= 2.0 storage.backoffs[threadIndex] *= 2.0
} else { } else {
storage.backoffs[threadIndex] = LIMIT_BACKOFF_TIME storage.backoffs[threadIndex] = LIMIT_BACKOFF_TIME
storage.backoffsRetries[threadIndex] += 1 storage.backoffsRetries[threadIndex] += 1
} }
delay := storage.backoffs[threadIndex] * rand.Float64() + storage.backoffs[threadIndex]*rand.Float64() delay := storage.backoffs[threadIndex]*rand.Float64() + storage.backoffs[threadIndex]*rand.Float64()
if storage.backoffs[threadIndex] >= LIMIT_BACKOFF_TIME { if storage.backoffs[threadIndex] >= LIMIT_BACKOFF_TIME {
callerChain:=findCallerChain() callerChain := findCallerChain()
LOG_INFO("GCD_RETRY", "Thread: %3d. Message:%s. Retrying after %6.2f seconds. Current backoff: %6.2f. Number of retries: %2d. caller chain: %s", threadIndex, message, delay, storage.backoffs[threadIndex], storage.backoffsRetries[threadIndex], callerChain) LOG_INFO("GCD_RETRY", "Thread: %3d. Message:%s. Retrying after %6.2f seconds. Current backoff: %6.2f. Number of retries: %2d. caller chain: %s", threadIndex, message, delay, storage.backoffs[threadIndex], storage.backoffsRetries[threadIndex], callerChain)
} }
time.Sleep(time.Duration(delay * float64(time.Second))) time.Sleep(time.Duration(delay * float64(time.Second)))
return true, nil return true, nil
} }
func findCallerChain() string { func findCallerChain() string {
@@ -321,17 +322,17 @@ func CreateGCDStorage(tokenFile string, storagePath string, threads int) (storag
return nil, err return nil, err
} }
storage = &GCDStorage { storage = &GCDStorage{
service: service, service: service,
numberOfThreads: threads, numberOfThreads: threads,
idCache: make(map[string]string), idCache: make(map[string]string),
idCacheLock: &sync.Mutex{}, idCacheLock: &sync.Mutex{},
backoffs: make([]float64, threads), backoffs: make([]float64, threads),
backoffsRetries:make([]int, threads), backoffsRetries: make([]int, threads),
} }
for b := range storage.backoffs { for b := range storage.backoffs {
storage.backoffs[b] = 0.1 * float64(storage.numberOfThreads) // at the first error, we should still sleep some amount storage.backoffs[b] = 0.1 * float64(storage.numberOfThreads) // at the first error, we should still sleep some amount
} }
storagePathID, err := storage.getIDFromPath(0, storagePath) storagePathID, err := storage.getIDFromPath(0, storagePath)