Fail-fast option added (#377)

Fail-fast option added.
This commit is contained in:
Danny 2022-07-21 10:59:11 -04:00 committed by GitHub
parent fe92d7c9db
commit dfcba3bf0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -43,8 +43,9 @@ type GraphConnector struct {
}
type graphService struct {
client msgraphsdk.GraphServiceClient
adapter msgraphsdk.GraphRequestAdapter
client msgraphsdk.GraphServiceClient
adapter msgraphsdk.GraphRequestAdapter
failFast bool // if true service will exit sequence upon encountering an error
}
func NewGraphConnector(acct account.Account) (*GraphConnector, error) {
@ -59,7 +60,7 @@ func NewGraphConnector(acct account.Account) (*GraphConnector, error) {
statusCh: make(chan *support.ConnectorOperationStatus),
credentials: m365,
}
aService, err := gc.createService()
aService, err := gc.createService(false)
if err != nil {
return nil, err
}
@ -86,17 +87,21 @@ func createAdapter(tenant, client, secret string) (*msgraphsdk.GraphRequestAdapt
}
// createSubConnector private constructor method for subConnector
func (gc *GraphConnector) createService() (*graphService, error) {
func (gc *GraphConnector) createService(shouldFailFast bool) (*graphService, error) {
adapter, err := createAdapter(gc.credentials.TenantID, gc.credentials.ClientID, gc.credentials.ClientSecret)
if err != nil {
return nil, err
}
connector := graphService{
adapter: *adapter,
client: *msgraphsdk.NewGraphServiceClient(adapter),
adapter: *adapter,
client: *msgraphsdk.NewGraphServiceClient(adapter),
failFast: shouldFailFast,
}
return &connector, err
}
func (gs *graphService) EnableFailFast() {
gs.failFast = true
}
// createMailFolder will create a mail folder iff a folder of the same name does not exit
func createMailFolder(gc graphService, user, folder string) (models.MailFolderable, error) {
@ -350,7 +355,7 @@ func (gc *GraphConnector) serializeMessages(ctx context.Context, user string) (m
// return empty collection when no items found
return nil, err
}
service, err := gc.createService()
service, err := gc.createService(gc.failFast)
if err != nil {
return nil, support.WrapAndAppend(user, err, err)
}
@ -396,6 +401,9 @@ func (sc *graphService) populateFromTaskList(
errs = support.WrapAndAppendf(edc.user, err, errs)
success--
}
if errs != nil && sc.failFast {
break
}
}
edc.FinishPopulation()