[FA-misc] Saga seems to work, fixed a UserNovelDataService bug

This commit is contained in:
gamer147
2026-01-28 12:11:06 -05:00
parent 579e05b853
commit ec967770d3
34 changed files with 1341 additions and 97 deletions

View File

@@ -21,6 +21,17 @@ public class ChapterPullRequestedConsumer : IConsumer<IChapterPullRequested>
public async Task Consume(ConsumeContext<IChapterPullRequested> context)
{
var message = context.Message;
await _novelUpdateService.PullChapterContents(message.NovelId, message.VolumeId, message.ChapterOrder);
var (chapter, imageCount) = await _novelUpdateService.PullChapterContents(
message.ImportId,
message.NovelId,
message.VolumeId,
message.ChapterOrder);
await context.Publish<IChapterPullCompleted>(new ChapterPullCompleted(
message.ImportId,
chapter.Id,
imageCount
));
}
}

View File

@@ -0,0 +1,43 @@
using FictionArchive.Service.NovelService.Services;
using FictionArchive.Service.Shared.Contracts.Events;
using MassTransit;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace FictionArchive.Service.NovelService.Consumers;
public class NovelImportCompletedConsumer : IConsumer<INovelImportCompleted>
{
private readonly ILogger<NovelImportCompletedConsumer> _logger;
private readonly NovelServiceDbContext _dbContext;
public NovelImportCompletedConsumer(
ILogger<NovelImportCompletedConsumer> logger,
NovelServiceDbContext dbContext)
{
_logger = logger;
_dbContext = dbContext;
}
public async Task Consume(ConsumeContext<INovelImportCompleted> context)
{
var message = context.Message;
_logger.LogInformation(
"Novel import {ImportId} completed. Success: {Success}, NovelId: {NovelId}, Error: {Error}",
message.ImportId,
message.Success,
message.NovelId,
message.ErrorMessage);
// Remove from ActiveImports to allow future imports
var activeImport = await _dbContext.ActiveImports
.FirstOrDefaultAsync(a => a.ImportId == message.ImportId);
if (activeImport != null)
{
_dbContext.ActiveImports.Remove(activeImport);
await _dbContext.SaveChangesAsync();
}
}
}

View File

@@ -0,0 +1,29 @@
using FictionArchive.Service.NovelService.Services;
using FictionArchive.Service.Shared.Contracts.Events;
using MassTransit;
using Microsoft.Extensions.Logging;
namespace FictionArchive.Service.NovelService.Consumers;
public class NovelImportRequestedConsumer : IConsumer<INovelImportRequested>
{
private readonly ILogger<NovelImportRequestedConsumer> _logger;
private readonly NovelUpdateService _novelUpdateService;
public NovelImportRequestedConsumer(
ILogger<NovelImportRequestedConsumer> logger,
NovelUpdateService novelUpdateService)
{
_logger = logger;
_novelUpdateService = novelUpdateService;
}
public async Task Consume(ConsumeContext<INovelImportRequested> context)
{
var message = context.Message;
_logger.LogInformation("Starting novel import for {NovelUrl} with ImportId {ImportId}",
message.NovelUrl, message.ImportId);
await _novelUpdateService.ImportNovel(message.ImportId, message.NovelUrl);
}
}

View File

@@ -1,26 +0,0 @@
using FictionArchive.Service.NovelService.Services;
using FictionArchive.Service.Shared.Contracts.Events;
using MassTransit;
using Microsoft.Extensions.Logging;
namespace FictionArchive.Service.NovelService.Consumers;
public class NovelUpdateRequestedConsumer : IConsumer<INovelUpdateRequested>
{
private readonly ILogger<NovelUpdateRequestedConsumer> _logger;
private readonly NovelUpdateService _novelUpdateService;
public NovelUpdateRequestedConsumer(
ILogger<NovelUpdateRequestedConsumer> logger,
NovelUpdateService novelUpdateService)
{
_logger = logger;
_novelUpdateService = novelUpdateService;
}
public async Task Consume(ConsumeContext<INovelUpdateRequested> context)
{
var message = context.Message;
await _novelUpdateService.ImportNovel(message.NovelUrl);
}
}