[FA-misc] Saga seems to work, fixed a UserNovelDataService bug
This commit is contained in:
@@ -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
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user