From 511bc05cb4c6707109fd6c3534d67722521015bb Mon Sep 17 00:00:00 2001 From: Christian Arenas Date: Wed, 17 May 2017 19:41:49 +0200 Subject: [PATCH] Remove SagaManagerIntegrationEventService frrom SagaManager and remove GracePeriod from dockercompose --- docker-compose.override.yml | 1 - ... => GracePeriodConfirmedIntegrationEvent.cs} | 4 ++-- .../ISagaManagerIntegrationEventService.cs | 9 --------- .../SagaManagerIntegrationEventService.cs | 17 ----------------- src/Services/SagaManager/SagaManager/Program.cs | 7 +++---- .../SagaManager/SagaManagerSettings.cs | 4 +++- .../SagaManager/Services/SagaManagerService.cs | 16 ++++++++-------- .../SagaManager/SagaManager/appsettings.json | 4 +++- 8 files changed, 19 insertions(+), 43 deletions(-) rename src/Services/SagaManager/SagaManager/IntegrationEvents/Events/{ConfirmGracePeriodCommand.cs => GracePeriodConfirmedIntegrationEvent.cs} (51%) delete mode 100644 src/Services/SagaManager/SagaManager/IntegrationEvents/ISagaManagerIntegrationEventService.cs delete mode 100644 src/Services/SagaManager/SagaManager/IntegrationEvents/SagaManagerIntegrationEventService.cs diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 0e752fb0e..ae42cb438 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -11,7 +11,6 @@ services: environment: - ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word - EventBusConnection=rabbitmq - - GracePeriod=15 #In minutes basket.api: environment: diff --git a/src/Services/SagaManager/SagaManager/IntegrationEvents/Events/ConfirmGracePeriodCommand.cs b/src/Services/SagaManager/SagaManager/IntegrationEvents/Events/GracePeriodConfirmedIntegrationEvent.cs similarity index 51% rename from src/Services/SagaManager/SagaManager/IntegrationEvents/Events/ConfirmGracePeriodCommand.cs rename to src/Services/SagaManager/SagaManager/IntegrationEvents/Events/GracePeriodConfirmedIntegrationEvent.cs index fd507a265..0eb422d6f 100644 --- a/src/Services/SagaManager/SagaManager/IntegrationEvents/Events/ConfirmGracePeriodCommand.cs +++ b/src/Services/SagaManager/SagaManager/IntegrationEvents/Events/GracePeriodConfirmedIntegrationEvent.cs @@ -2,10 +2,10 @@ { using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; - public class ConfirmGracePeriodCommand : IntegrationEvent + public class GracePeriodConfirmedIntegrationEvent : IntegrationEvent { public int OrderId { get;} - public ConfirmGracePeriodCommand(int orderId) => OrderId = orderId; + public GracePeriodConfirmedIntegrationEvent(int orderId) => OrderId = orderId; } } \ No newline at end of file diff --git a/src/Services/SagaManager/SagaManager/IntegrationEvents/ISagaManagerIntegrationEventService.cs b/src/Services/SagaManager/SagaManager/IntegrationEvents/ISagaManagerIntegrationEventService.cs deleted file mode 100644 index 41407702d..000000000 --- a/src/Services/SagaManager/SagaManager/IntegrationEvents/ISagaManagerIntegrationEventService.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace SagaManager.IntegrationEvents -{ - using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; - - public interface ISagaManagerIntegrationEventService - { - void PublishThroughEventBus(IntegrationEvent evt); - } -} \ No newline at end of file diff --git a/src/Services/SagaManager/SagaManager/IntegrationEvents/SagaManagerIntegrationEventService.cs b/src/Services/SagaManager/SagaManager/IntegrationEvents/SagaManagerIntegrationEventService.cs deleted file mode 100644 index 5107881ef..000000000 --- a/src/Services/SagaManager/SagaManager/IntegrationEvents/SagaManagerIntegrationEventService.cs +++ /dev/null @@ -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); - } -} \ No newline at end of file diff --git a/src/Services/SagaManager/SagaManager/Program.cs b/src/Services/SagaManager/SagaManager/Program.cs index 97784fc85..5e07bddad 100644 --- a/src/Services/SagaManager/SagaManager/Program.cs +++ b/src/Services/SagaManager/SagaManager/Program.cs @@ -14,7 +14,6 @@ using Microsoft.Extensions.Options; using RabbitMQ.Client; using Services; - using IntegrationEvents; public class Program { @@ -34,11 +33,13 @@ var sagaManagerService = serviceProvider .GetRequiredService(); + var checkUpdateTime = serviceProvider + .GetRequiredService>().Value.CheckUpdateTime; while (true) { sagaManagerService.CheckConfirmedGracePeriodOrders(); - await Task.Delay(90000); + await Task.Delay(checkUpdateTime); } } @@ -58,8 +59,6 @@ .AddOptions() .Configure(Configuration) .AddSingleton() - .AddSingleton() - .AddSingleton(sp => { var settings = sp.GetRequiredService>().Value; diff --git a/src/Services/SagaManager/SagaManager/SagaManagerSettings.cs b/src/Services/SagaManager/SagaManager/SagaManagerSettings.cs index ab9184b8a..3b6d3bd08 100644 --- a/src/Services/SagaManager/SagaManager/SagaManagerSettings.cs +++ b/src/Services/SagaManager/SagaManager/SagaManagerSettings.cs @@ -6,6 +6,8 @@ public string EventBusConnection { get; set; } - public int GracePeriod { get; set; } + public int GracePeriodTime { get; set; } + + public int CheckUpdateTime { get; set; } } } \ No newline at end of file diff --git a/src/Services/SagaManager/SagaManager/Services/SagaManagerService.cs b/src/Services/SagaManager/SagaManager/Services/SagaManagerService.cs index f7455e27c..fd5ab1438 100644 --- a/src/Services/SagaManager/SagaManager/Services/SagaManagerService.cs +++ b/src/Services/SagaManager/SagaManager/Services/SagaManagerService.cs @@ -5,21 +5,21 @@ using Microsoft.Extensions.Options; using Microsoft.Extensions.Logging; using Dapper; - using IntegrationEvents; using IntegrationEvents.Events; + using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; public class SagaManagerService : ISagaManagerService { private readonly SagaManagerSettings _settings; - private readonly ISagaManagerIntegrationEventService _sagaManagerIntegrationEventService; + private readonly IEventBus _eventBus; private readonly ILogger _logger; public SagaManagerService(IOptions settings, - ISagaManagerIntegrationEventService sagaManagerIntegrationEventService, + IEventBus eventBus, ILogger logger) { _settings = settings.Value; - _sagaManagerIntegrationEventService = sagaManagerIntegrationEventService; + _eventBus = eventBus; _logger = logger; } @@ -29,8 +29,8 @@ foreach (var orderId in orderIds) { - var confirmGracePeriodEvent = new ConfirmGracePeriodCommand(orderId); - _sagaManagerIntegrationEventService.PublishThroughEventBus(confirmGracePeriodEvent); + var confirmGracePeriodEvent = new GracePeriodConfirmedIntegrationEvent(orderId); + _eventBus.Publish(confirmGracePeriodEvent); } } @@ -45,9 +45,9 @@ conn.Open(); orderIds = conn.Query( @"SELECT Id FROM [Microsoft.eShopOnContainers.Services.OrderingDb].[ordering].[orders] - WHERE DATEDIFF(hour, [OrderDate], GETDATE()) >= @GracePeriod + WHERE DATEDIFF(hour, [OrderDate], GETDATE()) >= @GracePeriodTime AND [OrderStatusId] = 1", - new { GracePeriod = _settings.GracePeriod }); + new { GracePeriodTime = _settings.GracePeriodTime }); } catch (SqlException exception) { diff --git a/src/Services/SagaManager/SagaManager/appsettings.json b/src/Services/SagaManager/SagaManager/appsettings.json index 00472e82a..0a514a514 100644 --- a/src/Services/SagaManager/SagaManager/appsettings.json +++ b/src/Services/SagaManager/SagaManager/appsettings.json @@ -7,5 +7,7 @@ "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" }