[FA-misc] Reporting service seems to be working
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
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;
|
||||
|
||||
@@ -21,6 +23,11 @@ public class ChapterPullRequestedConsumer : IConsumer<IChapterPullRequested>
|
||||
public async Task Consume(ConsumeContext<IChapterPullRequested> 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,
|
||||
@@ -33,5 +40,10 @@ public class ChapterPullRequestedConsumer : IConsumer<IChapterPullRequested>
|
||||
chapter.Id,
|
||||
imageCount
|
||||
));
|
||||
|
||||
await context.ReportJobStatus(
|
||||
chapterJobId, "ChapterPull", $"Pull chapter {message.ChapterOrder}",
|
||||
JobStatus.Completed, parentJobId: message.ImportId,
|
||||
metadata: new Dictionary<string, string> { ["ChapterId"] = chapter.Id.ToString() });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using FictionArchive.Common.Enums;
|
||||
using FictionArchive.Service.Shared.Contracts.Events;
|
||||
using MassTransit;
|
||||
using NodaTime;
|
||||
@@ -49,6 +50,10 @@ public class NovelImportSaga : MassTransitStateMachine<NovelImportSagaState>
|
||||
ctx.Saga.StartedAt = _clock.GetCurrentInstant();
|
||||
})
|
||||
.TransitionTo(Importing)
|
||||
.PublishAsync(ctx => ctx.Init<IJobStatusUpdate>(new JobStatusUpdate(
|
||||
ctx.Saga.CorrelationId, null, "NovelImport",
|
||||
$"Import {ctx.Saga.NovelUrl}", JobStatus.InProgress,
|
||||
null, new Dictionary<string, string> { ["NovelUrl"] = ctx.Saga.NovelUrl })))
|
||||
);
|
||||
|
||||
During(Importing,
|
||||
@@ -68,7 +73,11 @@ public class NovelImportSaga : MassTransitStateMachine<NovelImportSagaState>
|
||||
ctx.Saga.CorrelationId,
|
||||
ctx.Saga.NovelId,
|
||||
true,
|
||||
null))),
|
||||
null)))
|
||||
.PublishAsync(ctx => ctx.Init<IJobStatusUpdate>(new JobStatusUpdate(
|
||||
ctx.Saga.CorrelationId, null, "NovelImport",
|
||||
$"Import {ctx.Saga.NovelUrl}", JobStatus.Completed,
|
||||
null, new Dictionary<string, string> { ["NovelId"] = ctx.Saga.NovelId.ToString() }))),
|
||||
elseBinder => elseBinder.TransitionTo(Processing)
|
||||
)
|
||||
);
|
||||
@@ -87,7 +96,11 @@ public class NovelImportSaga : MassTransitStateMachine<NovelImportSagaState>
|
||||
c.Saga.CorrelationId,
|
||||
c.Saga.NovelId,
|
||||
true,
|
||||
null)))),
|
||||
null)))
|
||||
.PublishAsync(c => c.Init<IJobStatusUpdate>(new JobStatusUpdate(
|
||||
c.Saga.CorrelationId, null, "NovelImport",
|
||||
$"Import {c.Saga.NovelUrl}", JobStatus.Completed,
|
||||
null, new Dictionary<string, string> { ["NovelId"] = c.Saga.NovelId.ToString() })))),
|
||||
|
||||
When(FileUploadStatusUpdate)
|
||||
.Then(ctx => ctx.Saga.CompletedImages++)
|
||||
@@ -98,7 +111,11 @@ public class NovelImportSaga : MassTransitStateMachine<NovelImportSagaState>
|
||||
c.Saga.CorrelationId,
|
||||
c.Saga.NovelId,
|
||||
true,
|
||||
null)))),
|
||||
null)))
|
||||
.PublishAsync(c => c.Init<IJobStatusUpdate>(new JobStatusUpdate(
|
||||
c.Saga.CorrelationId, null, "NovelImport",
|
||||
$"Import {c.Saga.NovelUrl}", JobStatus.Completed,
|
||||
null, new Dictionary<string, string> { ["NovelId"] = c.Saga.NovelId.ToString() })))),
|
||||
|
||||
When(ChapterPullFaulted)
|
||||
.Then(ctx =>
|
||||
@@ -111,7 +128,11 @@ public class NovelImportSaga : MassTransitStateMachine<NovelImportSagaState>
|
||||
ctx.Saga.CorrelationId,
|
||||
ctx.Saga.NovelId,
|
||||
false,
|
||||
ctx.Saga.ErrorMessage))),
|
||||
ctx.Saga.ErrorMessage)))
|
||||
.PublishAsync(ctx => ctx.Init<IJobStatusUpdate>(new JobStatusUpdate(
|
||||
ctx.Saga.CorrelationId, null, "NovelImport",
|
||||
$"Import {ctx.Saga.NovelUrl}", JobStatus.Failed,
|
||||
ctx.Saga.ErrorMessage, null))),
|
||||
|
||||
When(FileUploadFaulted)
|
||||
.Then(ctx =>
|
||||
@@ -125,6 +146,10 @@ public class NovelImportSaga : MassTransitStateMachine<NovelImportSagaState>
|
||||
ctx.Saga.NovelId,
|
||||
false,
|
||||
ctx.Saga.ErrorMessage)))
|
||||
.PublishAsync(ctx => ctx.Init<IJobStatusUpdate>(new JobStatusUpdate(
|
||||
ctx.Saga.CorrelationId, null, "NovelImport",
|
||||
$"Import {ctx.Saga.NovelUrl}", JobStatus.Failed,
|
||||
ctx.Saga.ErrorMessage, null)))
|
||||
);
|
||||
|
||||
SetCompletedWhenFinalized();
|
||||
|
||||
Reference in New Issue
Block a user