Auto retry export on collection failure

This commit is contained in:
Neeraj Gupta 2023-10-30 08:34:22 +05:30
parent 9135c91812
commit 6f11aa75b6
3 changed files with 30 additions and 12 deletions

View file

@ -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")
}

View file

@ -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 {

View file

@ -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 {