Tracks
- Track.IsPublished (migration marks existing tracks as published). New
tracks are created unpublished.
- PUT /tracks/{id}/published and PUT /tracks/published change the flag;
publishing requires completed audio processing (the batch endpoint
reports skipped tracks).
- An unpublished track is only visible to its owner. A WherePublished /
VisibleTo filter is applied to search, genres, listening history, last
listened, likes, mixes, album and playlist contents and counts, recently
listened albums, public user tracks, track details and stream tickets.
- isPublished is part of the track responses, GET /tracks/users/{userId}
accepts a published filter and status-counts reports published and
unpublished totals.
- CreateTrackRequest.pictureIntentId is optional: without it the track
uses the album cover or the preset picture and no picture processing
runs. CreateTrackResourcesEvent carries nullable picture fields, so
queues must be drained before deploying.
- POST /tracks/upload-urls accepts an audios list and one optional picture
shared by all of them, and returns an intent per file. The upload intent
limits are raised so a batch fits.
Albums
- AlbumType (Album, EP, Single) on create, update and responses.
- CreateAlbumRequest.trackIds creates the album and links the tracks in a
single save.
98 lines
4.3 KiB
C#
98 lines
4.3 KiB
C#
using MassTransit;
|
|
using Musify.Application.Events;
|
|
|
|
namespace Musify.Infrastructure.MassTransit.Sagas
|
|
{
|
|
public sealed class TrackProcessingStateMachine : MassTransitStateMachine<TrackProcessingState>
|
|
{
|
|
public State Processing { get; private set; } = null!;
|
|
public State Failed { get; private set; } = null!;
|
|
|
|
public Event<CreateTrackResourcesEvent> ProcessingStarted { get; private set; } = null!;
|
|
public Event<TrackPictureProcessed> PictureProcessed { get; private set; } = null!;
|
|
public Event<TrackAudioProcessed> AudioProcessed { get; private set; } = null!;
|
|
public Event<TrackPictureProcessingFailed> PictureFailed { get; private set; } = null!;
|
|
public Event<TrackAudioProcessingFailed> AudioFailed { get; private set; } = null!;
|
|
|
|
public TrackProcessingStateMachine()
|
|
{
|
|
InstanceState(state => state.CurrentState);
|
|
|
|
Event(() => ProcessingStarted, config => config.CorrelateById(context => context.Message.TrackId));
|
|
Event(() => PictureProcessed, config =>
|
|
{
|
|
config.CorrelateById(context => context.Message.TrackId);
|
|
config.OnMissingInstance(instance => instance.Discard());
|
|
});
|
|
Event(() => AudioProcessed, config =>
|
|
{
|
|
config.CorrelateById(context => context.Message.TrackId);
|
|
config.OnMissingInstance(instance => instance.Discard());
|
|
});
|
|
Event(() => PictureFailed, config =>
|
|
{
|
|
config.CorrelateById(context => context.Message.TrackId);
|
|
config.OnMissingInstance(instance => instance.Discard());
|
|
});
|
|
Event(() => AudioFailed, config =>
|
|
{
|
|
config.CorrelateById(context => context.Message.TrackId);
|
|
config.OnMissingInstance(instance => instance.Discard());
|
|
});
|
|
|
|
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;
|
|
context.Saga.PictureProcessed = context.Message.PictureDestinationKey == null;
|
|
context.Saga.AudioKey = context.Message.AudioDestinationKey;
|
|
})
|
|
.TransitionTo(Processing));
|
|
|
|
During(Processing,
|
|
When(PictureProcessed)
|
|
.Then(context =>
|
|
{
|
|
context.Saga.PictureProcessed = true;
|
|
context.Saga.UpdatedAt = DateTime.UtcNow;
|
|
})
|
|
.If(context => context.Saga.AudioProcessed, binder => binder.Finalize()),
|
|
When(AudioProcessed)
|
|
.Then(context =>
|
|
{
|
|
context.Saga.AudioProcessed = true;
|
|
context.Saga.UpdatedAt = DateTime.UtcNow;
|
|
})
|
|
.If(context => context.Saga.PictureProcessed, binder => binder.Finalize()),
|
|
When(PictureFailed)
|
|
.Then(context => context.Saga.UpdatedAt = DateTime.UtcNow)
|
|
.TransitionTo(Failed)
|
|
.Publish(context => new TrackProcessingFailed(
|
|
context.Saga.CorrelationId,
|
|
context.Saga.Bucket,
|
|
context.Saga.PictureKey,
|
|
context.Saga.AudioKey)),
|
|
When(AudioFailed)
|
|
.Then(context => context.Saga.UpdatedAt = DateTime.UtcNow)
|
|
.TransitionTo(Failed)
|
|
.Publish(context => new TrackProcessingFailed(
|
|
context.Saga.CorrelationId,
|
|
context.Saga.Bucket,
|
|
context.Saga.PictureKey,
|
|
context.Saga.AudioKey)));
|
|
|
|
During(Failed,
|
|
Ignore(PictureProcessed),
|
|
Ignore(AudioProcessed),
|
|
Ignore(PictureFailed),
|
|
Ignore(AudioFailed));
|
|
|
|
SetCompletedWhenFinalized();
|
|
}
|
|
}
|
|
}
|