feat(infra): playlist processing saga + generalize fault handling (phase 3)
Adds the PlayList picture-processing lifecycle saga (correlated by PlayListId)
mirroring the track one, and generalizes the failure plumbing:
- Rename the track fault translator to ProcessingSlipFaultConsumer and use a
generic Workflow.SubjectId variable + ProcessKind; it now emits typed
Track{Picture,Audio}/PlayListPicture ProcessingFailed events for all slips
- PlayListProcessingStateMachine (+ EF-persisted PlayListProcessingState,
migration): starts on CreatePlayListResourcesEvent, finalizes on
PlayListPictureProcessed, and on failure marks the playlist Failed and
removes the orphaned final picture (PlayListProcessingFailedConsumer +
MarkPlayListAsFailedActivity)
- UpdatePlayListPictureActivity publishes PlayListPictureProcessed on success
- Picture slip carries SubjectId + PlayListPicture kind + fault subscription
Verified end-to-end in Docker (RabbitMQ + migrated Postgres): both saga
endpoints, the fault translator and cleanup consumers configure, and an
addressing cross-check confirms all 21 activity execute queues the builders
address exist (caught + fixed a kebab mismatch on mark-play-list-as-failed).
Build: 0 warnings, 0 errors.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
using MassTransit;
|
||||
using Musify.Application.Events;
|
||||
|
||||
namespace Musify.Infrastructure.MassTransit.Sagas
|
||||
{
|
||||
public sealed class PlayListProcessingStateMachine : MassTransitStateMachine<PlayListProcessingState>
|
||||
{
|
||||
public State Processing { get; private set; } = null!;
|
||||
public State Failed { get; private set; } = null!;
|
||||
|
||||
public Event<CreatePlayListResourcesEvent> ProcessingStarted { get; private set; } = null!;
|
||||
public Event<PlayListPictureProcessed> PictureProcessed { get; private set; } = null!;
|
||||
public Event<PlayListPictureProcessingFailed> PictureFailed { get; private set; } = null!;
|
||||
|
||||
public PlayListProcessingStateMachine()
|
||||
{
|
||||
InstanceState(state => state.CurrentState);
|
||||
|
||||
Event(() => ProcessingStarted, config => config.CorrelateById(context => context.Message.PlayListId));
|
||||
Event(() => PictureProcessed, config => config.CorrelateById(context => context.Message.PlayListId));
|
||||
Event(() => PictureFailed, config => config.CorrelateById(context => context.Message.PlayListId));
|
||||
|
||||
Initially(
|
||||
When(ProcessingStarted)
|
||||
.Then(context =>
|
||||
{
|
||||
context.Saga.CreatedAt = DateTime.UtcNow;
|
||||
context.Saga.UpdatedAt = DateTime.UtcNow;
|
||||
context.Saga.Bucket = context.Message.Bucket;
|
||||
context.Saga.PictureKey = context.Message.PictureDestinationKey;
|
||||
})
|
||||
.TransitionTo(Processing));
|
||||
|
||||
During(Processing,
|
||||
When(PictureProcessed).Finalize(),
|
||||
When(PictureFailed)
|
||||
.Then(context => context.Saga.UpdatedAt = DateTime.UtcNow)
|
||||
.TransitionTo(Failed)
|
||||
.Publish(context => new PlayListProcessingFailed(
|
||||
context.Saga.CorrelationId,
|
||||
context.Saga.Bucket,
|
||||
context.Saga.PictureKey)));
|
||||
|
||||
During(Failed,
|
||||
Ignore(PictureProcessed),
|
||||
Ignore(PictureFailed));
|
||||
|
||||
SetCompletedWhenFinalized();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user