GC: exchange.Collection PopulateFunction refactor without TaskList (#441)
exchange.PopulateFunc executed without a tasklist.
This commit is contained in:
parent
9eb6a5dd0c
commit
e6f5b4515d
@ -68,23 +68,20 @@ func (eoc *Collection) PopulateCollection(newData *Stream) {
|
||||
}
|
||||
|
||||
// populateFromTaskList async call to fill DataCollection via channel implementation
|
||||
func PopulateFromCollection(
|
||||
func (edc *Collection) PopulateFromCollection(
|
||||
ctx context.Context,
|
||||
service graph.Service,
|
||||
collections map[string]*Collection,
|
||||
statusChannel chan<- *support.ConnectorOperationStatus,
|
||||
) {
|
||||
var errs error
|
||||
var attemptedItems, success int
|
||||
objectWriter := kw.NewJsonSerializationWriter()
|
||||
|
||||
for _, edc := range collections {
|
||||
|
||||
for _, task := range edc.jobs {
|
||||
response, err := service.Client().UsersById(edc.user).MessagesById(task).Get()
|
||||
if err != nil {
|
||||
details := support.ConnectorStackErrorTrace(err)
|
||||
errs = support.WrapAndAppend(edc.user, errors.Wrapf(err, "unable to retrieve %s, %s", task, details), errs)
|
||||
errs = support.WrapAndAppend(edc.user, errors.Wrapf(err, "unable to retrieve item %s; details %s", task, details), errs)
|
||||
continue
|
||||
}
|
||||
err = messageToDataCollection(service.Client(), ctx, objectWriter, edc.data, response, edc.user)
|
||||
@ -99,9 +96,8 @@ func PopulateFromCollection(
|
||||
}
|
||||
close(edc.data)
|
||||
attemptedItems += len(edc.jobs)
|
||||
}
|
||||
|
||||
status := support.CreateStatus(ctx, support.Backup, attemptedItems, success, len(collections), errs)
|
||||
status := support.CreateStatus(ctx, support.Backup, attemptedItems, success, 1, errs)
|
||||
logger.Ctx(ctx).Debug(status.String())
|
||||
statusChannel <- status
|
||||
}
|
||||
|
||||
@ -348,9 +348,10 @@ func (gc *GraphConnector) serializeMessages(ctx context.Context, user string) (m
|
||||
if err != nil {
|
||||
return nil, support.WrapAndAppend(user, err, err)
|
||||
}
|
||||
// async call to populate
|
||||
go exchange.PopulateFromCollection(ctx, service, collections, gc.statusCh)
|
||||
for _, edc := range collections {
|
||||
go edc.PopulateFromCollection(ctx, service, gc.statusCh)
|
||||
gc.incrementAwaitingMessages()
|
||||
}
|
||||
|
||||
return collections, err
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user