using FictionArchive.Common.Enums; using FictionArchive.Service.NovelService.Services; using FictionArchive.Service.Shared.Contracts.Events; using FictionArchive.Service.Shared.Extensions; using MassTransit; using Microsoft.Extensions.Logging; namespace FictionArchive.Service.NovelService.Consumers; public class ChapterPullRequestedConsumer : IConsumer { private readonly ILogger _logger; private readonly NovelUpdateService _novelUpdateService; public ChapterPullRequestedConsumer( ILogger logger, NovelUpdateService novelUpdateService) { _logger = logger; _novelUpdateService = novelUpdateService; } public async Task Consume(ConsumeContext context) { var message = context.Message; var chapterJobId = Guid.NewGuid(); await context.ReportJobStatus( chapterJobId, "ChapterPull", $"Pull chapter {message.ChapterOrder}", JobStatus.InProgress, parentJobId: message.ImportId); var (chapter, imageCount) = await _novelUpdateService.PullChapterContents( message.ImportId, message.NovelId, message.VolumeId, message.ChapterOrder); await context.Publish(new ChapterPullCompleted( message.ImportId, chapter.Id, imageCount )); await context.ReportJobStatus( chapterJobId, "ChapterPull", $"Pull chapter {message.ChapterOrder}", JobStatus.Completed, parentJobId: message.ImportId, metadata: new Dictionary { ["ChapterId"] = chapter.Id.ToString() }); } }