public async Task LoadEntitiesAsync(List <Entity> entities) { var batches = Batch(entities); var metrics = new DynamoDbMetrics("Batch Load", OperationType.Load); var batchMetrics = new ConcurrentBag <DynamoDbMetrics>(); await metrics.HandleAsync(Load(batchMetrics, batches)); metrics.Records = entities.Count; metrics.WriteCapacityUnits = batchMetrics.Sum(s => s.WriteCapacityUnits); metrics.Write(); }
async Task Load(ConcurrentBag <DynamoDbMetrics> batchMetrics, List <BatchWriteItemRequest> batches) { foreach (var batch in batches) { var batchMetric = new DynamoDbMetrics("Load", OperationType.Load); var response = await batchMetric.HandleAsync(client.BatchWriteItemAsync(batch)); if (response.UnprocessedItems.Any() || response.HttpStatusCode != HttpStatusCode.OK || response.ItemCollectionMetrics.Any() || response.ResponseMetadata.Metadata.Any()) { batchMetric.Error += JsonConvert.SerializeObject(response) + Environment.NewLine; } batchMetric.WriteCapacityUnits = response.ConsumedCapacity.Capacity; batchMetrics.Add(batchMetric); } }
public async Task GetEntityDetails(Guid entityId) { var request = new GetItemRequest { TableName = tableName, ReturnConsumedCapacity = "TOTAL", Key = new Dictionary <string, AttributeValue> { [nameof(Entity.EntityId)] = new AttributeValue(entityId.ToString()), } }; var metrics = new DynamoDbMetrics("Get Entity", OperationType.Get); var response = await metrics.HandleAsync(client.GetItemAsync(request)); metrics.ReadCapacityUnits = response.ConsumedCapacity.ReadCapacityUnits; metrics.WriteCapacityUnits = response.ConsumedCapacity.WriteCapacityUnits; }