[Bug Fix] GC: Backup: Onedrive: Context timeout during drive retrieval fix (#2046)
## Description Adds manual retry for drive retrieval <!-- Insert PR description--> ## Does this PR need a docs update or release note? - [x] ⛔ No ## Type of change <!--- Please check the type of change your PR introduces: ---> - [x] 🐛 Bugfix ## Issue(s) * closes Issue #2044<issue> ## Test Plan - [x] ⚡ Unit test
This commit is contained in:
parent
103f4ccd2c
commit
b769c288b7
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
msgraphgocore "github.com/microsoftgraph/msgraph-sdk-go-core"
|
msgraphgocore "github.com/microsoftgraph/msgraph-sdk-go-core"
|
||||||
msdrive "github.com/microsoftgraph/msgraph-sdk-go/drive"
|
msdrive "github.com/microsoftgraph/msgraph-sdk-go/drive"
|
||||||
@ -100,7 +101,11 @@ func siteDrives(ctx context.Context, service graph.Servicer, site string) ([]mod
|
|||||||
}
|
}
|
||||||
|
|
||||||
func userDrives(ctx context.Context, service graph.Servicer, user string) ([]models.Driveable, error) {
|
func userDrives(ctx context.Context, service graph.Servicer, user string) ([]models.Driveable, error) {
|
||||||
var hasDrive bool
|
var (
|
||||||
|
hasDrive bool
|
||||||
|
numberOfRetries = 3
|
||||||
|
r models.DriveCollectionResponseable
|
||||||
|
)
|
||||||
|
|
||||||
hasDrive, err := hasDriveLicense(ctx, service, user)
|
hasDrive, err := hasDriveLicense(ctx, service, user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -112,15 +117,30 @@ func userDrives(ctx context.Context, service graph.Servicer, user string) ([]mod
|
|||||||
return make([]models.Driveable, 0), nil // no license
|
return make([]models.Driveable, 0), nil // no license
|
||||||
}
|
}
|
||||||
|
|
||||||
r, err := service.Client().UsersById(user).Drives().Get(ctx, nil)
|
// Retry Loop for Drive retrieval. Request can timeout
|
||||||
if err != nil {
|
for i := 0; i <= numberOfRetries; i++ {
|
||||||
if strings.Contains(support.ConnectorStackErrorTrace(err), userDoesNotHaveDrive) {
|
r, err = service.Client().UsersById(user).Drives().Get(ctx, nil)
|
||||||
logger.Ctx(ctx).Debugf("User %s does not have a drive", user)
|
if err != nil {
|
||||||
return make([]models.Driveable, 0), nil // no license
|
detailedError := support.ConnectorStackErrorTrace(err)
|
||||||
|
if strings.Contains(detailedError, userDoesNotHaveDrive) {
|
||||||
|
logger.Ctx(ctx).Debugf("User %s does not have a drive", user)
|
||||||
|
return make([]models.Driveable, 0), nil // no license
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.Contains(detailedError, "context deadline exceeded") && i < numberOfRetries {
|
||||||
|
time.Sleep(time.Duration(3*(i+1)) * time.Second)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, errors.Wrapf(
|
||||||
|
err,
|
||||||
|
"failed to retrieve user drives. user: %s, details: %s",
|
||||||
|
user,
|
||||||
|
detailedError,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, errors.Wrapf(err, "failed to retrieve user drives. user: %s, details: %s",
|
break
|
||||||
user, support.ConnectorStackErrorTrace(err))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Ctx(ctx).Debugf("Found %d drives for user %s", len(r.GetValue()), user)
|
logger.Ctx(ctx).Debugf("Found %d drives for user %s", len(r.GetValue()), user)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user