Remove SagaManagerIntegrationEventService frrom SagaManager and remove GracePeriod from dockercompose
This commit is contained in:
parent
9b449461f2
commit
511bc05cb4
@ -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:
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
namespace SagaManager.IntegrationEvents
|
||||
{
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||
|
||||
public interface ISagaManagerIntegrationEventService
|
||||
{
|
||||
void PublishThroughEventBus(IntegrationEvent evt);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -6,6 +6,8 @@
|
||||
|
||||
public string EventBusConnection { get; set; }
|
||||
|
||||
public int GracePeriod { get; set; }
|
||||
public int GracePeriodTime { get; set; }
|
||||
|
||||
public int CheckUpdateTime { get; set; }
|
||||
}
|
||||
}
|
@ -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)
|
||||
{
|
||||
|
@ -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…
x
Reference in New Issue
Block a user