Exemplo n.º 1
0
        public async Task<CosmosBulkImportSummary> BulkInsertBatches(string collectionId, IEnumerable<IEnumerable<CosmosDocumentBase>> documentBatches, Action<CosmosBulkImportSummary> batchFinished = null)
        {
            try
            {
                var bulkExecutor = await GetAndInitializeBulkExecutor(collectionId);

                var jobSummray = new CosmosBulkImportSummary
                {
                    NumberOfBatches = documentBatches.Count()
                };

                foreach (var documentBatch in documentBatches)
                    await Task.Run(async () =>
                    {
                        var batchSummray = await BulkInsertAsync(bulkExecutor, documentBatch);

                        UpdateCosmosBulkImportSummary(jobSummray, batchSummray);
                        batchFinished?.Invoke(batchSummray);
                    });
                return jobSummray;
            }
            finally
            {
                PostBulkExecutor();
            }
        }
Exemplo n.º 2
0
        private void UpdateCosmosBulkImportSummary(CosmosBulkImportSummary jobSummray, CosmosBulkImportSummary batchSummray)
        {
            jobSummray.NumberOfDocumentsInserted += batchSummray.NumberOfDocumentsInserted;
            jobSummray.TotalRequestUnitsConsumed += batchSummray.TotalRequestUnitsConsumed;
            jobSummray.TotalTimeTaken += batchSummray.TotalTimeTaken;
            jobSummray.NumberOfBatchesCompleted++;

            batchSummray.NumberOfBatchesCompleted = jobSummray.NumberOfBatchesCompleted;
            batchSummray.NumberOfBatches = jobSummray.NumberOfBatches;
        }