Browse Source

Catalog. Fixed async/await misuses

pull/571/head
Marusyk 6 years ago
parent
commit
4e90b3f688
4 changed files with 9 additions and 9 deletions
  1. +2
    -2
      src/Services/Catalog/Catalog.API/Infrastructure/CatalogContextSeed.cs
  2. +4
    -4
      src/Services/Catalog/Catalog.API/IntegrationEvents/CatalogIntegrationEventService.cs
  3. +1
    -1
      src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/OrderStatusChangedToAwaitingValidationIntegrationEventHandler.cs
  4. +2
    -2
      src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/OrderStatusChangedToPaidIntegrationEventHandler.cs

+ 2
- 2
src/Services/Catalog/Catalog.API/Infrastructure/CatalogContextSeed.cs View File

@ -18,11 +18,11 @@
public class CatalogContextSeed
{
public async Task SeedAsync(CatalogContext context,IHostingEnvironment env,IOptions<CatalogSettings> settings,ILogger<CatalogContextSeed> logger)
public Task SeedAsync(CatalogContext context,IHostingEnvironment env,IOptions<CatalogSettings> settings,ILogger<CatalogContextSeed> logger)
{
var policy = CreatePolicy(logger, nameof(CatalogContextSeed));
await policy.ExecuteAsync(async () =>
return policy.ExecuteAsync(async () =>
{
var useCustomizationData = settings.Value.UseCustomizationData;
var contentRootPath = env.ContentRootPath;


+ 4
- 4
src/Services/Catalog/Catalog.API/IntegrationEvents/CatalogIntegrationEventService.cs View File

@ -27,18 +27,18 @@ namespace Catalog.API.IntegrationEvents
_eventLogService = _integrationEventLogServiceFactory(_catalogContext.Database.GetDbConnection());
}
public async Task PublishThroughEventBusAsync(IntegrationEvent evt)
public Task PublishThroughEventBusAsync(IntegrationEvent evt)
{
_eventBus.Publish(evt);
await _eventLogService.MarkEventAsPublishedAsync(evt);
return _eventLogService.MarkEventAsPublishedAsync(evt);
}
public async Task SaveEventAndCatalogContextChangesAsync(IntegrationEvent evt)
public Task SaveEventAndCatalogContextChangesAsync(IntegrationEvent evt)
{
//Use of an EF Core resiliency strategy when using multiple DbContexts within an explicit BeginTransaction():
//See: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency
await ResilientTransaction.New(_catalogContext)
return ResilientTransaction.New(_catalogContext)
.ExecuteAsync(async () => {
// Achieving atomicity between original catalog database operation and the IntegrationEventLog thanks to a local transaction
await _catalogContext.SaveChangesAsync();


+ 1
- 1
src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/OrderStatusChangedToAwaitingValidationIntegrationEventHandler.cs View File

@ -28,7 +28,7 @@
foreach (var orderStockItem in command.OrderStockItems)
{
var catalogItem = _catalogContext.CatalogItems.Find(orderStockItem.ProductId);
var catalogItem = await _catalogContext.CatalogItems.FindAsync(orderStockItem.ProductId);
var hasStock = catalogItem.AvailableStock >= orderStockItem.Units;
var confirmedOrderStockItem = new ConfirmedOrderStockItem(catalogItem.Id, hasStock);


+ 2
- 2
src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/OrderStatusChangedToPaidIntegrationEventHandler.cs View File

@ -15,7 +15,7 @@
_catalogContext = catalogContext;
}
public async Task Handle(OrderStatusChangedToPaidIntegrationEvent command)
public Task Handle(OrderStatusChangedToPaidIntegrationEvent command)
{
//we're not blocking stock/inventory
foreach (var orderStockItem in command.OrderStockItems)
@ -25,7 +25,7 @@
catalogItem.RemoveStock(orderStockItem.Units);
}
await _catalogContext.SaveChangesAsync();
return _catalogContext.SaveChangesAsync();
}
}
}

Loading…
Cancel
Save