소스 검색

Auto retry export on collection failure

Neeraj Gupta 1 년 전
부모
커밋
6f11aa75b6
3개의 변경된 파일30개의 추가작업 그리고 12개의 파일을 삭제
  1. 9 1
      pkg/model/errors.go
  2. 0 3
      pkg/model/remote.go
  3. 21 8
      pkg/sync.go

+ 9 - 1
pkg/model/errors.go

@@ -1,5 +1,13 @@
 package model
 
-import "errors"
+import (
+	"errors"
+	"strings"
+)
 
 var ErrDecryption = errors.New("error while decrypting the file")
+
+func ShouldRetrySync(err error) bool {
+	return strings.Contains(err.Error(), "read tcp") ||
+		strings.Contains(err.Error(), "dial tcp")
+}

+ 0 - 3
pkg/model/remote.go

@@ -142,9 +142,6 @@ func (r *RemoteFile) GetModificationTime() time.Time {
 }
 
 func (r *RemoteFile) GetLatlong() *export.Location {
-	if r.ID == 10698020 {
-		fmt.Println("found 10698020")
-	}
 	if r.PublicMetadata != nil {
 		// check if lat and long key exists
 		if lat, ok := r.PublicMetadata["lat"]; ok {

+ 21 - 8
pkg/sync.go

@@ -7,9 +7,9 @@ import (
 	"github.com/ente-io/cli/internal"
 	"github.com/ente-io/cli/internal/api"
 	"github.com/ente-io/cli/pkg/model"
-	"log"
-
 	bolt "go.etcd.io/bbolt"
+	"log"
+	"time"
 )
 
 func (c *ClICtrl) Export() error {
@@ -37,12 +37,23 @@ func (c *ClICtrl) Export() error {
 			continue
 		}
 		log.Println("start sync")
-		err = c.SyncAccount(account)
-		if err != nil {
-			fmt.Printf("Error syncing account %s: %s\n", account.Email, err)
-			return err
-		} else {
-			log.Println("sync done")
+		retryCount := 0
+		for {
+			err = c.SyncAccount(account)
+			if err != nil {
+				if model.ShouldRetrySync(err) && retryCount < 20 {
+					retryCount = retryCount + 1
+					timeInSecond := time.Duration(retryCount*10) * time.Second
+					log.Printf("Connection err, waiting for %s before trying again", timeInSecond.String())
+					time.Sleep(timeInSecond)
+					continue
+				}
+				fmt.Printf("Error syncing account %s: %s\n", account.Email, err)
+				return err
+			} else {
+				log.Println("sync done")
+				break
+			}
 		}
 
 	}
@@ -63,10 +74,12 @@ func (c *ClICtrl) SyncAccount(account model.Account) error {
 	err = c.fetchRemoteCollections(ctx)
 	if err != nil {
 		log.Printf("Error fetching collections: %s", err)
+		return err
 	}
 	err = c.fetchRemoteFiles(ctx)
 	if err != nil {
 		log.Printf("Error fetching files: %s", err)
+		return err
 	}
 	err = c.createLocalFolderForRemoteAlbums(ctx, account)
 	if err != nil {