Attach retry (#202)

Merge of Attach retry branch adds inline retry for attachments. Appropriate tests included.
This commit is contained in:
Danny 2022-06-16 07:05:29 -04:00 committed by GitHub
parent 15e7c102a4
commit 81bdc69c5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View File

@ -19,7 +19,10 @@ import (
"github.com/pkg/errors"
)
const mailCategory = "mail"
const (
numberOfRetries = 3
mailCategory = "mail"
)
// GraphConnector is a struct used to wrap the GraphServiceClient and
// GraphRequestAdapter from the msgraph-sdk-go. Additional fields are for
@ -246,11 +249,16 @@ func (gc *GraphConnector) serializeMessages(user string) ([]DataCollection, erro
return true
}
if *message.GetHasAttachments() {
attached, err := gc.client.UsersById(user).MessagesById(*message.GetId()).Attachments().Get()
if err == nil && attached != nil {
message.SetAttachments(attached.GetValue())
// Retry Loop
for count := 0; count < numberOfRetries; count++ {
attached, err := gc.client.UsersById(user).MessagesById(*message.GetId()).Attachments().Get()
if err == nil && attached != nil {
message.SetAttachments(attached.GetValue())
break
}
}
if err != nil {
fmt.Println("Retries exceeded")
errs = WrapAndAppend(*message.GetId(), fmt.Errorf("attachment failed: %v ", err), errs)
}
}

View File

@ -69,8 +69,9 @@ func (suite *GraphConnectorIntegrationSuite) TestGraphConnector_ExchangeDataColl
if err != nil {
suite.T().Logf("Missing Data: %s\n", err.Error())
}
suite.NotContains(err.Error(), "attachment failed") // TODO Create Retry Exceeded Error
exchangeData := collectionList[0]
suite.T().Logf("Full PathData: %s\n", exchangeData.FullPath())
suite.Greater(len(exchangeData.FullPath()), 2)
}
func (suite *GraphConnectorIntegrationSuite) TestGraphConnector_restoreMessages() {