Browse Source

Remove SagaManagerIntegrationEventService frrom SagaManager and remove GracePeriod from dockercompose

pull/809/head
Christian Arenas 7 years ago
parent
commit
def828aeda
8 changed files with 19 additions and 43 deletions
  1. +0
    -1
      docker-compose.override.yml
  2. +2
    -2
      src/Services/SagaManager/SagaManager/IntegrationEvents/Events/GracePeriodConfirmedIntegrationEvent.cs
  3. +0
    -9
      src/Services/SagaManager/SagaManager/IntegrationEvents/ISagaManagerIntegrationEventService.cs
  4. +0
    -17
      src/Services/SagaManager/SagaManager/IntegrationEvents/SagaManagerIntegrationEventService.cs
  5. +3
    -4
      src/Services/SagaManager/SagaManager/Program.cs
  6. +3
    -1
      src/Services/SagaManager/SagaManager/SagaManagerSettings.cs
  7. +8
    -8
      src/Services/SagaManager/SagaManager/Services/SagaManagerService.cs
  8. +3
    -1
      src/Services/SagaManager/SagaManager/appsettings.json

+ 0
- 1
docker-compose.override.yml View File

@ -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:


src/Services/SagaManager/SagaManager/IntegrationEvents/Events/ConfirmGracePeriodCommand.cs → src/Services/SagaManager/SagaManager/IntegrationEvents/Events/GracePeriodConfirmedIntegrationEvent.cs View File

@ -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;
}
}

+ 0
- 9
src/Services/SagaManager/SagaManager/IntegrationEvents/ISagaManagerIntegrationEventService.cs View File

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

+ 0
- 17
src/Services/SagaManager/SagaManager/IntegrationEvents/SagaManagerIntegrationEventService.cs 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);
}
}

+ 3
- 4
src/Services/SagaManager/SagaManager/Program.cs View File

@ -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<ISagaManagerService>();
var checkUpdateTime = serviceProvider
.GetRequiredService<IOptions<SagaManagerSettings>>().Value.CheckUpdateTime;
while (true)
{
sagaManagerService.CheckConfirmedGracePeriodOrders();
await Task.Delay(90000);
await Task.Delay(checkUpdateTime);
}
}
@ -58,8 +59,6 @@
.AddOptions()
.Configure<SagaManagerSettings>(Configuration)
.AddSingleton<ISagaManagerService, SagaManagerService>()
.AddSingleton<ISagaManagerIntegrationEventService, SagaManagerIntegrationEventService>()
.AddSingleton<IRabbitMQPersistentConnection>(sp =>
{
var settings = sp.GetRequiredService<IOptions<SagaManagerSettings>>().Value;


+ 3
- 1
src/Services/SagaManager/SagaManager/SagaManagerSettings.cs View File

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

+ 8
- 8
src/Services/SagaManager/SagaManager/Services/SagaManagerService.cs View File

@ -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<SagaManagerService> _logger;
public SagaManagerService(IOptions<SagaManagerSettings> settings,
ISagaManagerIntegrationEventService sagaManagerIntegrationEventService,
IEventBus eventBus,
ILogger<SagaManagerService> 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<int>(
@"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)
{


+ 3
- 1
src/Services/SagaManager/SagaManager/appsettings.json View File

@ -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"
}

Loading…
Cancel
Save