public async Task ProcessChangesAsync( IChangeFeedObserverContext context, IReadOnlyList <Document> docs, CancellationToken cancellationToken) { try { List <Document> transformedDocs = new List <Document>(); foreach (var doc in docs) { transformedDocs.AddRange(documentTransformer.TransformDocument(doc).Result); } BulkImportResponse bulkImportResponse = await bulkExecutor.BulkImportAsync( documents : transformedDocs, enableUpsert : true, maxConcurrencyPerPartitionKeyRange : 1, disableAutomaticIdGeneration : true, maxInMemorySortingBatchSize : null, cancellationToken : new CancellationToken()); LogMetrics(context, bulkImportResponse); } catch (Exception e) { Program.telemetryClient.TrackException(e); } Program.telemetryClient.Flush(); }
public async Task ProcessChangesAsync( IChangeFeedObserverContext context, IReadOnlyList <Document> docs, CancellationToken cancellationToken) { BulkImportResponse bulkImportResponse = new BulkImportResponse(); try { Boolean isSyntheticKey = SourcePartitionKeys.Contains(","); Boolean isNestedAttribute = SourcePartitionKeys.Contains("/"); List <Document> transformedDocs = new List <Document>(); Document document = new Document(); foreach (var doc in docs) { document = (SourcePartitionKeys != null & TargetPartitionKey != null) ? MapPartitionKey(doc, isSyntheticKey, TargetPartitionKey, isNestedAttribute, SourcePartitionKeys) : document = doc; transformedDocs.AddRange(documentTransformer.TransformDocument(document).Result); } bulkImportResponse = await bulkExecutor.BulkImportAsync( documents : transformedDocs, enableUpsert : true, maxConcurrencyPerPartitionKeyRange : 1, disableAutomaticIdGeneration : true, maxInMemorySortingBatchSize : null, cancellationToken : new CancellationToken(), maxMiniBatchSizeBytes : 100 * 1024); if (bulkImportResponse.FailedImports.Count > 0 && containerClient != null) { WriteFailedDocsToBlob("FailedImportDocs", containerClient, bulkImportResponse); } if (bulkImportResponse.BadInputDocuments.Count > 0 && containerClient != null) { WriteFailedDocsToBlob("BadInputDocs", containerClient, bulkImportResponse); } LogMetrics(context, bulkImportResponse); } catch (Exception e) { Program.telemetryClient.TrackException(e); } Program.telemetryClient.Flush(); }