Remove SagaManagerIntegrationEventService frrom SagaManager and remove GracePeriod from dockercompose

This commit is contained in:
Christian Arenas 2017-05-17 19:41:49 +02:00
parent 0ee173cd34
commit def828aeda
8 changed files with 19 additions and 43 deletions

View File

@ -11,7 +11,6 @@ services:
environment: environment:
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word - ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word
- EventBusConnection=rabbitmq - EventBusConnection=rabbitmq
- GracePeriod=15 #In minutes
basket.api: basket.api:
environment: environment:

View File

@ -2,10 +2,10 @@
{ {
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
public class ConfirmGracePeriodCommand : IntegrationEvent public class GracePeriodConfirmedIntegrationEvent : IntegrationEvent
{ {
public int OrderId { get;} public int OrderId { get;}
public ConfirmGracePeriodCommand(int orderId) => OrderId = orderId; public GracePeriodConfirmedIntegrationEvent(int orderId) => OrderId = orderId;
} }
} }

View File

@ -1,9 +0,0 @@
namespace SagaManager.IntegrationEvents
{
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
public interface ISagaManagerIntegrationEventService
{
void PublishThroughEventBus(IntegrationEvent evt);
}
}

View File

@ -1,17 +0,0 @@
namespace SagaManager.IntegrationEvents
{
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
using System;
public class SagaManagerIntegrationEventService : ISagaManagerIntegrationEventService
{
private readonly IEventBus _eventBus;
public SagaManagerIntegrationEventService(IEventBus eventBus)
=> _eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus));
public void PublishThroughEventBus(IntegrationEvent evt) => _eventBus.Publish(evt);
}
}

View File

@ -14,7 +14,6 @@
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using RabbitMQ.Client; using RabbitMQ.Client;
using Services; using Services;
using IntegrationEvents;
public class Program public class Program
{ {
@ -34,11 +33,13 @@
var sagaManagerService = serviceProvider var sagaManagerService = serviceProvider
.GetRequiredService<ISagaManagerService>(); .GetRequiredService<ISagaManagerService>();
var checkUpdateTime = serviceProvider
.GetRequiredService<IOptions<SagaManagerSettings>>().Value.CheckUpdateTime;
while (true) while (true)
{ {
sagaManagerService.CheckConfirmedGracePeriodOrders(); sagaManagerService.CheckConfirmedGracePeriodOrders();
await Task.Delay(90000); await Task.Delay(checkUpdateTime);
} }
} }
@ -58,8 +59,6 @@
.AddOptions() .AddOptions()
.Configure<SagaManagerSettings>(Configuration) .Configure<SagaManagerSettings>(Configuration)
.AddSingleton<ISagaManagerService, SagaManagerService>() .AddSingleton<ISagaManagerService, SagaManagerService>()
.AddSingleton<ISagaManagerIntegrationEventService, SagaManagerIntegrationEventService>()
.AddSingleton<IRabbitMQPersistentConnection>(sp => .AddSingleton<IRabbitMQPersistentConnection>(sp =>
{ {
var settings = sp.GetRequiredService<IOptions<SagaManagerSettings>>().Value; var settings = sp.GetRequiredService<IOptions<SagaManagerSettings>>().Value;

View File

@ -6,6 +6,8 @@
public string EventBusConnection { get; set; } public string EventBusConnection { get; set; }
public int GracePeriod { get; set; } public int GracePeriodTime { get; set; }
public int CheckUpdateTime { get; set; }
} }
} }

View File

@ -5,21 +5,21 @@
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Dapper; using Dapper;
using IntegrationEvents;
using IntegrationEvents.Events; using IntegrationEvents.Events;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
public class SagaManagerService : ISagaManagerService public class SagaManagerService : ISagaManagerService
{ {
private readonly SagaManagerSettings _settings; private readonly SagaManagerSettings _settings;
private readonly ISagaManagerIntegrationEventService _sagaManagerIntegrationEventService; private readonly IEventBus _eventBus;
private readonly ILogger<SagaManagerService> _logger; private readonly ILogger<SagaManagerService> _logger;
public SagaManagerService(IOptions<SagaManagerSettings> settings, public SagaManagerService(IOptions<SagaManagerSettings> settings,
ISagaManagerIntegrationEventService sagaManagerIntegrationEventService, IEventBus eventBus,
ILogger<SagaManagerService> logger) ILogger<SagaManagerService> logger)
{ {
_settings = settings.Value; _settings = settings.Value;
_sagaManagerIntegrationEventService = sagaManagerIntegrationEventService; _eventBus = eventBus;
_logger = logger; _logger = logger;
} }
@ -29,8 +29,8 @@
foreach (var orderId in orderIds) foreach (var orderId in orderIds)
{ {
var confirmGracePeriodEvent = new ConfirmGracePeriodCommand(orderId); var confirmGracePeriodEvent = new GracePeriodConfirmedIntegrationEvent(orderId);
_sagaManagerIntegrationEventService.PublishThroughEventBus(confirmGracePeriodEvent); _eventBus.Publish(confirmGracePeriodEvent);
} }
} }
@ -45,9 +45,9 @@
conn.Open(); conn.Open();
orderIds = conn.Query<int>( orderIds = conn.Query<int>(
@"SELECT Id FROM [Microsoft.eShopOnContainers.Services.OrderingDb].[ordering].[orders] @"SELECT Id FROM [Microsoft.eShopOnContainers.Services.OrderingDb].[ordering].[orders]
WHERE DATEDIFF(hour, [OrderDate], GETDATE()) >= @GracePeriod WHERE DATEDIFF(hour, [OrderDate], GETDATE()) >= @GracePeriodTime
AND [OrderStatusId] = 1", AND [OrderStatusId] = 1",
new { GracePeriod = _settings.GracePeriod }); new { GracePeriodTime = _settings.GracePeriodTime });
} }
catch (SqlException exception) catch (SqlException exception)
{ {

View File

@ -7,5 +7,7 @@
"Microsoft": "Information" "Microsoft": "Information"
} }
}, },
"ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;" "ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;",
"GracePeriodTime": "15",
"CheckUpdateTime": "30000"
} }