Skip to content

Commit def828a

Browse files
committed
Remove SagaManagerIntegrationEventService frrom SagaManager and remove GracePeriod from dockercompose
1 parent 0ee173c commit def828a

8 files changed

Lines changed: 19 additions & 43 deletions

File tree

docker-compose.override.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ services:
1111
environment:
1212
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word
1313
- EventBusConnection=rabbitmq
14-
- GracePeriod=15 #In minutes
1514

1615
basket.api:
1716
environment:

src/Services/SagaManager/SagaManager/IntegrationEvents/Events/ConfirmGracePeriodCommand.cs renamed to src/Services/SagaManager/SagaManager/IntegrationEvents/Events/GracePeriodConfirmedIntegrationEvent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
{
33
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
44

5-
public class ConfirmGracePeriodCommand : IntegrationEvent
5+
public class GracePeriodConfirmedIntegrationEvent : IntegrationEvent
66
{
77
public int OrderId { get;}
88

9-
public ConfirmGracePeriodCommand(int orderId) => OrderId = orderId;
9+
public GracePeriodConfirmedIntegrationEvent(int orderId) => OrderId = orderId;
1010
}
1111
}

src/Services/SagaManager/SagaManager/IntegrationEvents/ISagaManagerIntegrationEventService.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/Services/SagaManager/SagaManager/IntegrationEvents/SagaManagerIntegrationEventService.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/Services/SagaManager/SagaManager/Program.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
using Microsoft.Extensions.Options;
1515
using RabbitMQ.Client;
1616
using Services;
17-
using IntegrationEvents;
1817

1918
public class Program
2019
{
@@ -34,11 +33,13 @@ static async Task MainAsync()
3433

3534
var sagaManagerService = serviceProvider
3635
.GetRequiredService<ISagaManagerService>();
36+
var checkUpdateTime = serviceProvider
37+
.GetRequiredService<IOptions<SagaManagerSettings>>().Value.CheckUpdateTime;
3738

3839
while (true)
3940
{
4041
sagaManagerService.CheckConfirmedGracePeriodOrders();
41-
await Task.Delay(90000);
42+
await Task.Delay(checkUpdateTime);
4243
}
4344
}
4445

@@ -58,8 +59,6 @@ public static IServiceProvider ConfigureServices(IServiceCollection services)
5859
.AddOptions()
5960
.Configure<SagaManagerSettings>(Configuration)
6061
.AddSingleton<ISagaManagerService, SagaManagerService>()
61-
.AddSingleton<ISagaManagerIntegrationEventService, SagaManagerIntegrationEventService>()
62-
6362
.AddSingleton<IRabbitMQPersistentConnection>(sp =>
6463
{
6564
var settings = sp.GetRequiredService<IOptions<SagaManagerSettings>>().Value;

src/Services/SagaManager/SagaManager/SagaManagerSettings.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ public class SagaManagerSettings
66

77
public string EventBusConnection { get; set; }
88

9-
public int GracePeriod { get; set; }
9+
public int GracePeriodTime { get; set; }
10+
11+
public int CheckUpdateTime { get; set; }
1012
}
1113
}

src/Services/SagaManager/SagaManager/Services/SagaManagerService.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
using Microsoft.Extensions.Options;
66
using Microsoft.Extensions.Logging;
77
using Dapper;
8-
using IntegrationEvents;
98
using IntegrationEvents.Events;
9+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
1010

1111
public class SagaManagerService : ISagaManagerService
1212
{
1313
private readonly SagaManagerSettings _settings;
14-
private readonly ISagaManagerIntegrationEventService _sagaManagerIntegrationEventService;
14+
private readonly IEventBus _eventBus;
1515
private readonly ILogger<SagaManagerService> _logger;
1616

1717
public SagaManagerService(IOptions<SagaManagerSettings> settings,
18-
ISagaManagerIntegrationEventService sagaManagerIntegrationEventService,
18+
IEventBus eventBus,
1919
ILogger<SagaManagerService> logger)
2020
{
2121
_settings = settings.Value;
22-
_sagaManagerIntegrationEventService = sagaManagerIntegrationEventService;
22+
_eventBus = eventBus;
2323
_logger = logger;
2424
}
2525

@@ -29,8 +29,8 @@ public void CheckConfirmedGracePeriodOrders()
2929

3030
foreach (var orderId in orderIds)
3131
{
32-
var confirmGracePeriodEvent = new ConfirmGracePeriodCommand(orderId);
33-
_sagaManagerIntegrationEventService.PublishThroughEventBus(confirmGracePeriodEvent);
32+
var confirmGracePeriodEvent = new GracePeriodConfirmedIntegrationEvent(orderId);
33+
_eventBus.Publish(confirmGracePeriodEvent);
3434
}
3535
}
3636

@@ -45,9 +45,9 @@ private IEnumerable<int> GetConfirmedGracePeriodOrders()
4545
conn.Open();
4646
orderIds = conn.Query<int>(
4747
@"SELECT Id FROM [Microsoft.eShopOnContainers.Services.OrderingDb].[ordering].[orders]
48-
WHERE DATEDIFF(hour, [OrderDate], GETDATE()) >= @GracePeriod
48+
WHERE DATEDIFF(hour, [OrderDate], GETDATE()) >= @GracePeriodTime
4949
AND [OrderStatusId] = 1",
50-
new { GracePeriod = _settings.GracePeriod });
50+
new { GracePeriodTime = _settings.GracePeriodTime });
5151
}
5252
catch (SqlException exception)
5353
{

src/Services/SagaManager/SagaManager/appsettings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@
77
"Microsoft": "Information"
88
}
99
},
10-
"ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;"
10+
"ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;",
11+
"GracePeriodTime": "15",
12+
"CheckUpdateTime": "30000"
1113
}

0 commit comments

Comments
 (0)