From ae28971be3cc860d73d7326a42377e866d9673c9 Mon Sep 17 00:00:00 2001 From: ashmrtn <3891298+ashmrtn@users.noreply.github.com> Date: Thu, 1 Sep 2022 16:31:43 -0700 Subject: [PATCH] Thread contexts through some GC functions (#728) ## Description Will be used later and just generally useful if we ever add tracing or such to these functions. ## Type of change Please check the type of change your PR introduces: - [ ] :sunflower: Feature - [ ] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Test - [x] :hamster: Trivial/Minor ## Issue(s) #456 ## Test Plan - [ ] :muscle: Manual - [x] :zap: Unit test - [ ] :green_heart: E2E --- src/internal/connector/exchange/iterators_test.go | 3 +++ src/internal/connector/exchange/service_iterators.go | 7 +++++++ src/internal/connector/exchange/service_query.go | 3 +++ src/internal/connector/graph_connector.go | 2 +- 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/internal/connector/exchange/iterators_test.go b/src/internal/connector/exchange/iterators_test.go index 7310c295f..0c8797d72 100644 --- a/src/internal/connector/exchange/iterators_test.go +++ b/src/internal/connector/exchange/iterators_test.go @@ -1,6 +1,7 @@ package exchange import ( + "context" "testing" absser "github.com/microsoft/kiota-abstractions-go/serialization" @@ -75,6 +76,7 @@ func loadService(t *testing.T) *exchangeService { // functions are valid for current versioning of msgraph-go-sdk func (suite *ExchangeIteratorSuite) TestIterativeFunctions() { var ( + ctx = context.Background() t = suite.T() mailScope, contactScope selectors.ExchangeScope userID = tester.M365UserID(t) @@ -141,6 +143,7 @@ func (suite *ExchangeIteratorSuite) TestIterativeFunctions() { // callbackFunc iterates through all models.Messageable and fills exchange.Collection.jobs[] // with corresponding item IDs. New collections are created for each directory callbackFunc := test.iterativeFunction( + ctx, userID, test.scope, errs, false, diff --git a/src/internal/connector/exchange/service_iterators.go b/src/internal/connector/exchange/service_iterators.go index 04305ebe1..7fcdbf50e 100644 --- a/src/internal/connector/exchange/service_iterators.go +++ b/src/internal/connector/exchange/service_iterators.go @@ -1,6 +1,7 @@ package exchange import ( + "context" "fmt" "github.com/microsoftgraph/msgraph-sdk-go/models" @@ -29,6 +30,7 @@ type displayable interface { // GraphIterateFuncs are iterate functions to be used with the M365 iterators (e.g. msgraphgocore.NewPageIterator) // @returns a callback func that works with msgraphgocore.PageIterator.Iterate function type GraphIterateFunc func( + ctx context.Context, user string, scope selectors.ExchangeScope, errs error, @@ -43,6 +45,7 @@ type GraphIterateFunc func( // objects belonging to any folder are // placed into a Collection based on the parent folder func IterateSelectAllDescendablesForCollections( + ctx context.Context, user string, scope selectors.ExchangeScope, errs error, @@ -108,6 +111,7 @@ func IterateSelectAllDescendablesForCollections( // and storing events in collections based on // the calendarID which originates from M365. func IterateSelectAllEventsForCollections( + ctx context.Context, user string, scope selectors.ExchangeScope, errs error, @@ -191,6 +195,7 @@ func IterateSelectAllEventsForCollections( // that places exchange mail message ids belonging to specific directories // into a Collection. Messages outside of those directories are omitted. func IterateAndFilterMessagesForCollections( + ctx context.Context, user string, scope selectors.ExchangeScope, errs error, @@ -204,6 +209,7 @@ func IterateAndFilterMessagesForCollections( return func(messageItem any) bool { if !isFilterSet { err := CollectMailFolders( + ctx, scope, user, collections, @@ -237,6 +243,7 @@ func IterateAndFilterMessagesForCollections( } func IterateFilterFolderDirectoriesForCollections( + ctx context.Context, user string, scope selectors.ExchangeScope, errs error, diff --git a/src/internal/connector/exchange/service_query.go b/src/internal/connector/exchange/service_query.go index f43567205..a5d5c04b6 100644 --- a/src/internal/connector/exchange/service_query.go +++ b/src/internal/connector/exchange/service_query.go @@ -1,6 +1,7 @@ package exchange import ( + "context" "fmt" absser "github.com/microsoft/kiota-abstractions-go/serialization" @@ -124,6 +125,7 @@ func RetrieveMessageDataForUser(gs graph.Service, user, m365ID string) (absser.P } func CollectMailFolders( + ctx context.Context, scope selectors.ExchangeScope, user string, collections map[string]*Collection, @@ -155,6 +157,7 @@ func CollectMailFolders( } callbackFunc := IterateFilterFolderDirectoriesForCollections( + ctx, user, scope, err, diff --git a/src/internal/connector/graph_connector.go b/src/internal/connector/graph_connector.go index 38fff9e67..901523a21 100644 --- a/src/internal/connector/graph_connector.go +++ b/src/internal/connector/graph_connector.go @@ -350,7 +350,7 @@ func (gc *GraphConnector) createCollections( // callbackFunc iterates through all M365 object target and fills exchange.Collection.jobs[] // with corresponding item M365IDs. New collections are created for each directory. // Each directory used the M365 Identifier. The use of ID stops collisions betweens users - callbackFunc := gIter(user, scope, errs, gc.failFast, gc.credentials, collections, gc.statusCh) + callbackFunc := gIter(ctx, user, scope, errs, gc.failFast, gc.credentials, collections, gc.statusCh) iterateError := pageIterator.Iterate(callbackFunc) if iterateError != nil {