Add transaction support between services

This commit is contained in:
2025-10-27 18:09:09 +09:00
parent 6b3733001a
commit 9e526c54fa
11 changed files with 75 additions and 44 deletions

View File

@ -20,24 +20,23 @@ namespace Hcs.WebApp.BackgroundServices
{
await InitializeStateAsync();
using var scope = scopeFactory.CreateScope();
var headquartersService = scope.ServiceProvider.GetRequiredService<HeadquartersService>();
while (!stoppingToken.IsCancellationRequested)
{
while (campaignManagementState.TryDequeueCampaign(out var campaign))
{
if (stoppingToken.IsCancellationRequested) return;
using var scope = scopeFactory.CreateScope();
try
{
var manager = managerFactory.CreateManager(campaign);
var manager = managerFactory.CreateManager(scope, campaign);
await manager.StartAsync(stoppingToken);
managers.Add(manager);
}
catch (Exception e)
{
var headquartersService = scope.ServiceProvider.GetRequiredService<HeadquartersService>();
await headquartersService.SetCampaignEndedWithFail(campaign.Id, e.Message);
}
}