Fixes
This commit is contained in:
@@ -19,16 +19,16 @@ namespace Musify.Application.Configuration
|
||||
public string ParentFolder { get; set; } = "Tracks";
|
||||
|
||||
[Required]
|
||||
public string OriginalPictures { get; set; } = "OriginalTracks";
|
||||
public string OriginalPictures { get; set; } = "OriginalPictures";
|
||||
|
||||
[Required]
|
||||
public string SmallPictures { get; set; } = "SmallTracks";
|
||||
public string SmallPictures { get; set; } = "SmallPictures";
|
||||
|
||||
[Required]
|
||||
public string MediumPictures { get; set; } = "MediumTracks";
|
||||
public string MediumPictures { get; set; } = "MediumPictures";
|
||||
|
||||
[Required]
|
||||
public string LargePictures { get; set; } = "LargeTracks";
|
||||
public string LargePictures { get; set; } = "LargePictures";
|
||||
|
||||
[Required]
|
||||
public string PresetOriginalPicture { get; set; } = "PresetOriginalPicture.webp";
|
||||
@@ -43,7 +43,10 @@ namespace Musify.Application.Configuration
|
||||
public string PresetLargePicture { get; set; } = "PresetLargePicture.webp";
|
||||
|
||||
[Required]
|
||||
public string Audios { get; set; } = "Audios";
|
||||
public string OriginalAudios { get; set; } = "OriginalAudios";
|
||||
|
||||
[Required]
|
||||
public string ProcessedAudio { get; set; } = "ProcessedAudios";
|
||||
}
|
||||
|
||||
public class TrackPicturesSizes
|
||||
|
||||
+3
-2
@@ -1,8 +1,9 @@
|
||||
namespace Musify.Application.Events
|
||||
{
|
||||
public record TranscodeAudioFromTrackEvent(
|
||||
public record UpdateTrackAudioEvent(
|
||||
Guid TrackId,
|
||||
string SourceBucketName,
|
||||
string SourceKeyName,
|
||||
string DestinationBucketName,
|
||||
string DestinationKeyName);
|
||||
string DestinationFolderKeyName);
|
||||
}
|
||||
@@ -56,7 +56,10 @@ namespace Musify.Application.PlayLists.Handlers
|
||||
{
|
||||
var imageId = Guid.NewGuid();
|
||||
var pictureName = imageId + picture.FileType;
|
||||
var pictureStorageKey = Path.Join(playListConfiguration.Routes.OriginalPictures, pictureName);
|
||||
var pictureStorageKey = Path.Join(
|
||||
playListConfiguration.Routes.ParentFolders,
|
||||
playListConfiguration.Routes.OriginalPictures,
|
||||
pictureName);
|
||||
|
||||
var uploadResult = await UploadFile(picture, pictureStorageKey, cancellationToken);
|
||||
|
||||
@@ -97,12 +100,15 @@ namespace Musify.Application.PlayLists.Handlers
|
||||
async Task PublishUpdateEvent(string originalPictureKeyName, PlayList playList, CancellationToken cancellationToken)
|
||||
{
|
||||
var smallPictureKeyName = Path.Combine(
|
||||
playListConfiguration.Routes.ParentFolders,
|
||||
playListConfiguration.Routes.SmallPictures,
|
||||
$"{playList.Id}.{pictureHandler.FileExtension}");
|
||||
var mediumPictureKeyName = Path.Combine(
|
||||
playListConfiguration.Routes.ParentFolders,
|
||||
playListConfiguration.Routes.MediumPictures,
|
||||
$"{playList.Id}.{pictureHandler.FileExtension}");
|
||||
var largePictureKeyName = Path.Combine(
|
||||
playListConfiguration.Routes.ParentFolders,
|
||||
playListConfiguration.Routes.LargePictures,
|
||||
$"{playList.Id}.{pictureHandler.FileExtension}");
|
||||
|
||||
|
||||
@@ -31,24 +31,35 @@ namespace Musify.Application.PlayLists.Handlers
|
||||
var keysToRemove = new List<string>();
|
||||
|
||||
if (playList.SmallPictureKeyName != playListConfiguration.Routes.PresetSmallPicture)
|
||||
{
|
||||
keysToRemove.Add(playList.SmallPictureKeyName);
|
||||
}
|
||||
keysToRemove.Add(Path.Combine(
|
||||
playListConfiguration.Routes.ParentFolders,
|
||||
playListConfiguration.Routes.SmallPictures,
|
||||
playList.SmallPictureKeyName));
|
||||
if (playList.MediumPictureKeyName != playListConfiguration.Routes.PresetMediumPicture)
|
||||
{
|
||||
keysToRemove.Add(playList.MediumPictureKeyName);
|
||||
}
|
||||
keysToRemove.Add(Path.Combine(
|
||||
playListConfiguration.Routes.ParentFolders,
|
||||
playListConfiguration.Routes.MediumPictures,
|
||||
playList.MediumPictureKeyName));
|
||||
if (playList.LargePictureKeyName != playListConfiguration.Routes.PresetLargePicture)
|
||||
{
|
||||
keysToRemove.Add(playList.LargePictureKeyName);
|
||||
}
|
||||
keysToRemove.Add(Path.Combine(
|
||||
playListConfiguration.Routes.ParentFolders,
|
||||
playListConfiguration.Routes.LargePictures,
|
||||
playList.LargePictureKeyName));
|
||||
|
||||
foreach (var key in keysToRemove)
|
||||
{
|
||||
var publishResult = await TryPublishRemoveFileEventAsync(playList.Id, key, cancellationToken);
|
||||
|
||||
if (!publishResult.IsSuccess && !publishResult.IsNotFound())
|
||||
if (!publishResult.IsSuccess)
|
||||
{
|
||||
if (publishResult.IsNotFound())
|
||||
{
|
||||
logger.LogWarning("File with key={KeyName} not found in storage while trying to publish remove file event for PlayList with id={PlayListId}.", key, playList.Id);
|
||||
continue;
|
||||
}
|
||||
|
||||
return publishResult;
|
||||
}
|
||||
}
|
||||
|
||||
database.PlayLists.Remove(playList);
|
||||
|
||||
@@ -52,17 +52,17 @@ namespace Musify.Application.PlayLists.Handlers
|
||||
}
|
||||
|
||||
if (playList.SmallPictureKeyName != playListConfiguration.Routes.PresetSmallPicture)
|
||||
{
|
||||
await PublishRemoveFileEvent(playList.SmallPictureKeyName, cancellationToken);
|
||||
}
|
||||
await PublishRemoveFileEvent(Path.Combine(
|
||||
playListConfiguration.Routes.SmallPictures,
|
||||
playList.SmallPictureKeyName), cancellationToken);
|
||||
if (playList.MediumPictureKeyName != playListConfiguration.Routes.PresetMediumPicture)
|
||||
{
|
||||
await PublishRemoveFileEvent(playList.MediumPictureKeyName, cancellationToken);
|
||||
}
|
||||
await PublishRemoveFileEvent(Path.Combine(
|
||||
playListConfiguration.Routes.MediumPictures,
|
||||
playList.MediumPictureKeyName), cancellationToken);
|
||||
if (playList.LargePictureKeyName != playListConfiguration.Routes.PresetLargePicture)
|
||||
{
|
||||
await PublishRemoveFileEvent(playList.LargePictureKeyName, cancellationToken);
|
||||
}
|
||||
await PublishRemoveFileEvent(Path.Combine(
|
||||
playListConfiguration.Routes.LargePictures,
|
||||
playList.LargePictureKeyName), cancellationToken);
|
||||
|
||||
var newImageId = Guid.NewGuid();
|
||||
var pictureName = newImageId + request.NewPicture.FileType;
|
||||
@@ -99,7 +99,9 @@ namespace Musify.Application.PlayLists.Handlers
|
||||
{
|
||||
await eventBus.PublishAsync(new RemoveFileEvent(
|
||||
storageConfiguration.BucketName,
|
||||
keyName), cancellationToken);
|
||||
Path.Combine(
|
||||
playListConfiguration.Routes.ParentFolders,
|
||||
keyName)), cancellationToken);
|
||||
|
||||
return Result.NoContent();
|
||||
}
|
||||
|
||||
@@ -25,17 +25,23 @@ namespace Musify.Application.Tracks.Handler
|
||||
return Result.NotFound($"User with id {request.UserId} not found");
|
||||
}
|
||||
|
||||
var originalPictureKeyName = Path.Combine(trackConfiguration.Routes.OriginalPictures, Guid.NewGuid() + request.Picture.FileType);
|
||||
var originalPictureFileName = Guid.NewGuid() + request.Picture.FileType;
|
||||
var originalAudioFileName = Guid.NewGuid() + request.Audio.FileType;
|
||||
var track = new Track
|
||||
{
|
||||
Title = request.Title,
|
||||
NormalizedTitle = request.Title.Trim().ToUpperInvariant(),
|
||||
OriginalPictureKeyName = originalPictureKeyName,
|
||||
OriginalPictureKeyName = originalPictureFileName,
|
||||
OriginalAudioKeyName = originalAudioFileName,
|
||||
SmallPictureKeyName = trackConfiguration.Routes.PresetSmallPicture,
|
||||
MediumPictureKeyName = trackConfiguration.Routes.PresetMediumPicture,
|
||||
LargePictureKeyName = trackConfiguration.Routes.PresetLargePicture,
|
||||
};
|
||||
|
||||
var originalPictureKeyName = Path.Combine(
|
||||
trackConfiguration.Routes.ParentFolder,
|
||||
trackConfiguration.Routes.OriginalPictures,
|
||||
originalPictureFileName);
|
||||
var pictureUploadResult = await UploadFile(request.Picture, originalPictureKeyName, cancellationToken);
|
||||
if (!pictureUploadResult.IsSuccess)
|
||||
{
|
||||
@@ -44,7 +50,10 @@ namespace Musify.Application.Tracks.Handler
|
||||
}
|
||||
|
||||
|
||||
var audioKeyName = Path.Combine(trackConfiguration.Routes.Audios, Guid.NewGuid() + request.Audio.FileType);
|
||||
var audioKeyName = Path.Combine(
|
||||
trackConfiguration.Routes.ParentFolder,
|
||||
trackConfiguration.Routes.OriginalAudios,
|
||||
Guid.NewGuid() + request.Audio.FileType);
|
||||
var audioUploadResult = await UploadFile(request.Audio, audioKeyName, cancellationToken);
|
||||
if (!audioUploadResult.IsSuccess)
|
||||
{
|
||||
@@ -93,12 +102,15 @@ namespace Musify.Application.Tracks.Handler
|
||||
async Task PublishUpdateEvent(string originalPictureKeyName, Track track, CancellationToken cancellationToken)
|
||||
{
|
||||
var smallPictureKeyName = Path.Combine(
|
||||
trackConfiguration.Routes.ParentFolder,
|
||||
trackConfiguration.Routes.SmallPictures,
|
||||
$"{track.Id}.{pictureHandler.FileExtension}");
|
||||
var mediumPictureKeyName = Path.Combine(
|
||||
trackConfiguration.Routes.ParentFolder,
|
||||
trackConfiguration.Routes.MediumPictures,
|
||||
$"{track.Id}.{pictureHandler.FileExtension}");
|
||||
var largePictureKeyName = Path.Combine(
|
||||
trackConfiguration.Routes.ParentFolder,
|
||||
trackConfiguration.Routes.LargePictures,
|
||||
$"{track.Id}.{pictureHandler.FileExtension}");
|
||||
|
||||
@@ -119,15 +131,17 @@ namespace Musify.Application.Tracks.Handler
|
||||
|
||||
async Task PublishTranscodeEvent(Guid trackId, string audioKeyName, CancellationToken cancellationToken)
|
||||
{
|
||||
var destinationAudioKeyName = Path.Combine(
|
||||
trackConfiguration.Routes.Audios,
|
||||
trackId.ToString());
|
||||
var destinationFolderAudio = Path.Combine(
|
||||
trackConfiguration.Routes.ParentFolder,
|
||||
trackConfiguration.Routes.ProcessedAudio,
|
||||
Guid.NewGuid().ToString());
|
||||
|
||||
await eventBus.PublishAsync(new TranscodeAudioFromTrackEvent(
|
||||
await eventBus.PublishAsync(new UpdateTrackAudioEvent(
|
||||
trackId,
|
||||
storageConfiguration.BucketName,
|
||||
audioKeyName,
|
||||
storageConfiguration.BucketName,
|
||||
destinationAudioKeyName), cancellationToken);
|
||||
destinationFolderAudio), cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,13 @@ namespace Musify.Domain.Entities
|
||||
[MaxLength(64)]
|
||||
public required string LargePictureKeyName { get; set; }
|
||||
|
||||
[Required]
|
||||
[MaxLength(64)]
|
||||
public required string OriginalAudioKeyName { get; set; }
|
||||
|
||||
[MaxLength(64)]
|
||||
public string AudioFolderKeyName { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public DateTime CreatedDate { get; set; } = DateTime.UtcNow;
|
||||
|
||||
|
||||
@@ -38,9 +38,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="MassTransit\Activities\Audio\" />
|
||||
<Folder Include="MassTransit\Activities\Pictures\" />
|
||||
<Folder Include="MassTransit\Logs\" />
|
||||
<Folder Include="MassTransit\RoutingSlip\Variables\" />
|
||||
<Folder Include="MassTransit\Filters\" />
|
||||
<Folder Include="MassTransit\EventBus\" />
|
||||
|
||||
@@ -39,21 +39,23 @@ namespace Musify.Infrastructure.Messaging.Activities
|
||||
|
||||
try
|
||||
{
|
||||
await using var fileStream = File.OpenRead(sourceFilePath);
|
||||
|
||||
var result = await audioTranscoder.TranscodeToDashAsync(
|
||||
fileStream,
|
||||
workingDirectory,
|
||||
executeContext.CancellationToken);
|
||||
|
||||
if (!result.IsSuccess)
|
||||
await using (var fileStream = File.OpenRead(sourceFilePath))
|
||||
{
|
||||
var errorMessage = string.Join("; ", result.Errors);
|
||||
logger.LogError("Transcoding failed for file {SourceFilePath}. Errors: {ErrorMessage}",
|
||||
sourceFilePath, errorMessage);
|
||||
throw new Exception(errorMessage);
|
||||
var result = await audioTranscoder.TranscodeToDashAsync(
|
||||
fileStream,
|
||||
workingDirectory,
|
||||
executeContext.CancellationToken);
|
||||
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
var errorMessage = string.Join("; ", result.Errors);
|
||||
logger.LogError("Transcoding failed for file {SourceFilePath}. Errors: {ErrorMessage}",
|
||||
sourceFilePath, errorMessage);
|
||||
throw new Exception(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
File.Delete(sourceFilePath);
|
||||
await processTrackingStore.CompleteStepAsync(processId, stepId, executeContext.CancellationToken);
|
||||
return executeContext.Completed();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
using MassTransit;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Musify.Application.Contracts.Infrastructure;
|
||||
using Musify.Domain.Entities;
|
||||
using Musify.Infrastructure.MassTransit.Arguments;
|
||||
using Musify.Infrastructure.MassTransit.Logs;
|
||||
using Musify.Infrastructure.Messaging.Activities;
|
||||
|
||||
namespace Musify.Infrastructure.MassTransit.Activities.Audio
|
||||
{
|
||||
public class UpdateTrackAudioActivity(
|
||||
IDatabase database,
|
||||
ILogger<TranscodeDashAudioActivity> logger,
|
||||
IProcessTrackingStore processTrackingStore)
|
||||
: IActivity<UpdateTrackAudioArguments, UpdateTrackAudioLog>
|
||||
{
|
||||
public const string ExecuteEndpointName = "update-track-audio";
|
||||
|
||||
public async Task<ExecutionResult> Execute(ExecuteContext<UpdateTrackAudioArguments> executeContext)
|
||||
{
|
||||
var processId = await processTrackingStore.GetOrCreateProcessAsync(
|
||||
"RoutingSlip",
|
||||
executeContext.CorrelationId ?? executeContext.TrackingNumber,
|
||||
executeContext.ConversationId,
|
||||
executeContext.MessageId,
|
||||
executeContext.CancellationToken);
|
||||
|
||||
var stepId = await processTrackingStore.StartStepAsync(
|
||||
processId,
|
||||
nameof(UpdateTrackAudioActivity),
|
||||
ProcessStepComponentType.Activity,
|
||||
0,
|
||||
executeContext.CancellationToken);
|
||||
|
||||
try
|
||||
{
|
||||
var track = await database.Tracks.FindAsync(
|
||||
[executeContext.Arguments.TrackId],
|
||||
cancellationToken: executeContext.CancellationToken);
|
||||
|
||||
if (track is null)
|
||||
{
|
||||
logger.LogWarning("Track with id {TrackId} not found",
|
||||
executeContext.Arguments.TrackId);
|
||||
throw new InvalidOperationException($"Track with id {executeContext.Arguments.TrackId} not found");
|
||||
}
|
||||
|
||||
var log = new UpdateTrackAudioLog(
|
||||
track.Id,
|
||||
track.AudioFolderKeyName);
|
||||
|
||||
track.AudioFolderKeyName = Path.GetFileName(executeContext.Arguments.AudioFolderKeyName);
|
||||
|
||||
database.Tracks.Update(track);
|
||||
await database.SaveChangesAsync(executeContext.CancellationToken);
|
||||
|
||||
logger.LogInformation("Updated Track {TrackId} audio",
|
||||
executeContext.Arguments.TrackId);
|
||||
|
||||
await processTrackingStore.CompleteStepAsync(processId, stepId, executeContext.CancellationToken);
|
||||
return executeContext.Completed();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Error updating Track {TrackId} audio",
|
||||
executeContext.Arguments.TrackId);
|
||||
await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<CompensationResult> Compensate(CompensateContext<UpdateTrackAudioLog> compensateContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
var track = await database.Tracks.FindAsync(
|
||||
[compensateContext.Log.TrackId],
|
||||
cancellationToken: compensateContext.CancellationToken);
|
||||
|
||||
if (track is null)
|
||||
{
|
||||
return compensateContext.Compensated();
|
||||
}
|
||||
|
||||
track.AudioFolderKeyName = compensateContext.Log.PreviousFolderAudioKeyName;
|
||||
|
||||
database.Tracks.Update(track);
|
||||
await database.SaveChangesAsync(compensateContext.CancellationToken);
|
||||
|
||||
return compensateContext.Compensated();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Error compensating Track {TrackId} audio", compensateContext.Log.TrackId);
|
||||
return compensateContext.Failed(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ namespace Musify.Infrastructure.Messaging.Activities
|
||||
try
|
||||
{
|
||||
var uploadedKeys = Directory.GetFiles(folderPath)
|
||||
.Select(file => $"{destinationKeyName}/{Path.GetFileName(file) }")
|
||||
.Select(file => Path.Combine(destinationKeyName, Path.GetFileName(file)))
|
||||
.ToArray();
|
||||
|
||||
var transferFilesResult = await storageHandler.TransferFilesAsync(
|
||||
|
||||
@@ -51,10 +51,10 @@ namespace Musify.Infrastructure.Messaging.Activities
|
||||
playList.MediumPictureKeyName,
|
||||
playList.LargePictureKeyName);
|
||||
|
||||
playList.OriginalPictureKeyName = executeContext.Arguments.OriginalPictureKeyName;
|
||||
playList.SmallPictureKeyName = executeContext.Arguments.SmallPictureKeyName;
|
||||
playList.MediumPictureKeyName = executeContext.Arguments.MediumPictureKeyName;
|
||||
playList.LargePictureKeyName = executeContext.Arguments.LargePictureKeyName;
|
||||
playList.OriginalPictureKeyName = Path.GetFileName(executeContext.Arguments.OriginalPictureKeyName);
|
||||
playList.SmallPictureKeyName = Path.GetFileName(executeContext.Arguments.SmallPictureKeyName);
|
||||
playList.MediumPictureKeyName = Path.GetFileName(executeContext.Arguments.MediumPictureKeyName);
|
||||
playList.LargePictureKeyName = Path.GetFileName(executeContext.Arguments.LargePictureKeyName);
|
||||
|
||||
database.PlayLists.Update(playList);
|
||||
await database.SaveChangesAsync(executeContext.CancellationToken);
|
||||
|
||||
@@ -51,10 +51,10 @@ namespace Musify.Infrastructure.Messaging.Activities
|
||||
track.MediumPictureKeyName,
|
||||
track.LargePictureKeyName);
|
||||
|
||||
track.OriginalPictureKeyName = executeContext.Arguments.OriginalPictureKeyName;
|
||||
track.SmallPictureKeyName = executeContext.Arguments.SmallPictureKeyName;
|
||||
track.MediumPictureKeyName = executeContext.Arguments.MediumPictureKeyName;
|
||||
track.LargePictureKeyName = executeContext.Arguments.LargePictureKeyName;
|
||||
track.OriginalPictureKeyName = Path.GetFileName(executeContext.Arguments.OriginalPictureKeyName);
|
||||
track.SmallPictureKeyName = Path.GetFileName(executeContext.Arguments.SmallPictureKeyName);
|
||||
track.MediumPictureKeyName = Path.GetFileName(executeContext.Arguments.MediumPictureKeyName);
|
||||
track.LargePictureKeyName = Path.GetFileName(executeContext.Arguments.LargePictureKeyName);
|
||||
|
||||
database.Tracks.Update(track);
|
||||
await database.SaveChangesAsync(executeContext.CancellationToken);
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Musify.Infrastructure.MassTransit.Arguments
|
||||
{
|
||||
public record UpdateTrackAudioArguments(
|
||||
Guid TrackId,
|
||||
string AudioFolderKeyName);
|
||||
}
|
||||
+5
-5
@@ -2,16 +2,16 @@
|
||||
using Musify.Application.Events;
|
||||
using Musify.Infrastructure.Messaging.RoutingSlip.Builders;
|
||||
|
||||
namespace Musify.Infrastructure.Messaging.Consumers
|
||||
namespace Musify.Infrastructure.MassTransit.Consumers
|
||||
{
|
||||
public class TranscodeAudioFromTrackConsumer(
|
||||
public class UpdateTrackAudioConsumer(
|
||||
IBus bus,
|
||||
AudioWorkflowRoutingSlipBuilder routingSlipBuilder)
|
||||
: IConsumer<TranscodeAudioFromTrackEvent>
|
||||
: IConsumer<UpdateTrackAudioEvent>
|
||||
{
|
||||
public const string QueueName = "transcode-audio-from-track";
|
||||
public const string QueueName = "update-track-audio";
|
||||
|
||||
public async Task Consume(ConsumeContext<TranscodeAudioFromTrackEvent> consumeContext)
|
||||
public async Task Consume(ConsumeContext<UpdateTrackAudioEvent> consumeContext)
|
||||
{
|
||||
var routingSlip = routingSlipBuilder
|
||||
.Build(consumeContext.Message, consumeContext.CorrelationId)
|
||||
@@ -1,7 +1,10 @@
|
||||
using MassTransit;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Musify.Infrastructure.Configuration;
|
||||
using Musify.Infrastructure.MassTransit.Activities.Audio;
|
||||
using Musify.Infrastructure.MassTransit.Arguments;
|
||||
using Musify.Infrastructure.MassTransit.Consumers;
|
||||
using Musify.Infrastructure.MassTransit.Logs;
|
||||
using Musify.Infrastructure.Messaging.Activities;
|
||||
using Musify.Infrastructure.Messaging.Activities.Arguments;
|
||||
using Musify.Infrastructure.Messaging.Activities.Logs;
|
||||
@@ -36,9 +39,9 @@ namespace Musify.Infrastructure.Messaging
|
||||
{
|
||||
options.AddConsumer<UpdatePlayListPictureConsumer>();
|
||||
options.AddConsumer<RemoveFileConsumer>();
|
||||
options.AddConsumer<TranscodeAudioFromTrackConsumer>();
|
||||
options.AddConsumer<UpdateTrackPictureConsumer>();
|
||||
options.AddConsumer<RoutingSlipCleanUpConsumer>();
|
||||
options.AddConsumer<UpdateTrackAudioConsumer>();
|
||||
|
||||
options.AddExecuteActivity<RemoveFileFromBucketActivity, RemoveFileFromBucketArguments>();
|
||||
options.AddExecuteActivity<GenerateAudioWorkflowPathsActivity, GenerateAudioWorkflowPathsArguments>();
|
||||
@@ -50,6 +53,7 @@ namespace Musify.Infrastructure.Messaging
|
||||
options.AddActivity<DownloadFileFromBucketActivity, DownloadFileFromBucketArguments, DownloadFileFromBucketLog>();
|
||||
options.AddActivity<TranscodeDashAudioActivity, TranscodeDashAudioArguments, TranscodeDashAudioLog>();
|
||||
options.AddActivity<TransferFilesToBucketActivity, TransferFilesToBucketArguments, TransferFilesToBucketLog>();
|
||||
options.AddActivity<UpdateTrackAudioActivity, UpdateTrackAudioArguments, UpdateTrackAudioLog>();
|
||||
|
||||
options.UsingRabbitMq((busRegistrationContext, busFactoryConfigurator) =>
|
||||
{
|
||||
@@ -69,9 +73,9 @@ namespace Musify.Infrastructure.Messaging
|
||||
endpointConfigurator.ConfigureConsumer<RemoveFileConsumer>(busRegistrationContext);
|
||||
} );
|
||||
|
||||
busFactoryConfigurator.ReceiveEndpoint(TranscodeAudioFromTrackConsumer.QueueName, endpointConfigurator =>
|
||||
busFactoryConfigurator.ReceiveEndpoint(UpdateTrackAudioConsumer.QueueName, endpointConfigurator =>
|
||||
{
|
||||
endpointConfigurator.ConfigureConsumer<TranscodeAudioFromTrackConsumer>(busRegistrationContext);
|
||||
endpointConfigurator.ConfigureConsumer<UpdateTrackAudioConsumer>(busRegistrationContext);
|
||||
} );
|
||||
|
||||
busFactoryConfigurator.ReceiveEndpoint(UpdateTrackPictureConsumer.QueueName, endpointConfigurator =>
|
||||
|
||||
@@ -14,5 +14,6 @@ namespace Musify.Infrastructure.Messaging.RoutingSlip
|
||||
internal const string DeleteOriginal = "DeleteOriginal";
|
||||
internal const string UpdateTrackPicture = "UpdateTrackPicture";
|
||||
internal const string UpdatePlayListPicture = "UpdatePlayListPicture";
|
||||
internal const string UpdateTrackAudio = "UpdateTrackAudio";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ using MassTransit;
|
||||
using MassTransit.Courier.Contracts;
|
||||
using Musify.Application.Events;
|
||||
using Musify.Infrastructure.Configuration;
|
||||
using Musify.Infrastructure.MassTransit.Activities.Audio;
|
||||
using Musify.Infrastructure.MassTransit.Arguments;
|
||||
using Musify.Infrastructure.MassTransit.Consumers;
|
||||
using Musify.Infrastructure.Messaging.Activities;
|
||||
using Musify.Infrastructure.Messaging.Activities.Arguments;
|
||||
@@ -11,7 +13,7 @@ namespace Musify.Infrastructure.Messaging.RoutingSlip.Builders
|
||||
{
|
||||
public class AudioWorkflowRoutingSlipBuilder(WorkerConfiguration workerConfiguration)
|
||||
{
|
||||
public RoutingSlipBuilder Build(TranscodeAudioFromTrackEvent message, Guid? correlationId)
|
||||
public RoutingSlipBuilder Build(UpdateTrackAudioEvent message, Guid? correlationId)
|
||||
{
|
||||
var routingSlipBuilder = new RoutingSlipBuilder(NewId.NextGuid());
|
||||
|
||||
@@ -49,7 +51,14 @@ namespace Musify.Infrastructure.Messaging.RoutingSlip.Builders
|
||||
new TransferFilesToBucketArguments(
|
||||
message.DestinationBucketName,
|
||||
RoutingSlipVariableNames.Audio.TranscodedDirectory,
|
||||
message.DestinationKeyName));
|
||||
message.DestinationFolderKeyName));
|
||||
|
||||
routingSlipBuilder.AddActivity(
|
||||
ActivityNames.UpdateTrackAudio,
|
||||
MessagingHelper.BuildExecuteActivityUri(UpdateTrackAudioActivity.ExecuteEndpointName),
|
||||
new UpdateTrackAudioArguments(
|
||||
message.TrackId,
|
||||
message.DestinationFolderKeyName));
|
||||
|
||||
return routingSlipBuilder;
|
||||
}
|
||||
|
||||
@@ -130,11 +130,6 @@ namespace Musify.Infrastructure.Messaging.RoutingSlip.Builders
|
||||
largePictureWidth,
|
||||
largePictureHeight);
|
||||
|
||||
routingSlipBuilder.AddActivity(
|
||||
ActivityNames.DeleteOriginal,
|
||||
MessagingHelper.BuildExecuteActivityUri(RemoveFileFromBucketActivity.ExecuteEndpointName),
|
||||
new RemoveFileFromBucketArguments(sourceBucketName, sourceKeyName));
|
||||
|
||||
routingSlipBuilder.AddActivity(
|
||||
ActivityNames.UploadFiles,
|
||||
MessagingHelper.BuildExecuteActivityUri(TransferFilesToBucketActivity.ExecuteEndpointName),
|
||||
|
||||
+11
-1
@@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
namespace Musify.Infrastructure.Persistence.Migrations
|
||||
{
|
||||
[DbContext(typeof(Database))]
|
||||
[Migration("20260324183733_FirstMigration")]
|
||||
[Migration("20260325003221_FirstMigration")]
|
||||
partial class FirstMigration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@@ -195,6 +195,11 @@ namespace Musify.Infrastructure.Persistence.Migrations
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("AudioFolderKeyName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)");
|
||||
|
||||
b.Property<DateTime>("CreatedDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
@@ -213,6 +218,11 @@ namespace Musify.Infrastructure.Persistence.Migrations
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)");
|
||||
|
||||
b.Property<string>("OriginalAudioKeyName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)");
|
||||
|
||||
b.Property<string>("OriginalPictureKeyName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
+2
@@ -41,6 +41,8 @@ namespace Musify.Infrastructure.Persistence.Migrations
|
||||
SmallPictureKeyName = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
||||
MediumPictureKeyName = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
||||
LargePictureKeyName = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
||||
OriginalAudioKeyName = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
||||
AudioFolderKeyName = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
||||
CreatedDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
UpdatedDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
@@ -192,6 +192,11 @@ namespace Musify.Infrastructure.Persistence.Migrations
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("AudioFolderKeyName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)");
|
||||
|
||||
b.Property<DateTime>("CreatedDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
@@ -210,6 +215,11 @@ namespace Musify.Infrastructure.Persistence.Migrations
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)");
|
||||
|
||||
b.Property<string>("OriginalAudioKeyName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)");
|
||||
|
||||
b.Property<string>("OriginalPictureKeyName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
|
||||
@@ -80,27 +80,28 @@ namespace Musify.Infrastructure.Storage
|
||||
string fileName = Path.GetFileName(file);
|
||||
string filePath = Path.Combine(sourceDirectory, file);
|
||||
|
||||
var keyName = Path.Combine(route, fileName);
|
||||
var upload = new Upload
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
BucketName = bucketName,
|
||||
KeyName = $"{route}/{fileName}",
|
||||
KeyName = keyName,
|
||||
ContentType = "Application/Octet-Stream"
|
||||
};
|
||||
await database.Uploads.AddAsync(upload, cancellationToken);
|
||||
|
||||
try
|
||||
{
|
||||
await trasnsferUtility.UploadAsync(filePath, bucketName, fileName, cancellationToken);
|
||||
await trasnsferUtility.UploadAsync(filePath, bucketName, keyName, cancellationToken);
|
||||
upload.State = UploadState.Successful;
|
||||
successCount++;
|
||||
logger.LogDebug("Transferred file to S3. Bucket: {BucketName}, Route: {Route}, File: {FileName}", bucketName, route, fileName);
|
||||
logger.LogDebug("Transferred file to S3. Bucket: {BucketName}, KeyName: {KeyName}", bucketName, keyName);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
failedCount++;
|
||||
upload.State = UploadState.Failed;
|
||||
logger.LogError(exception, "Failed to transfer file to S3. Bucket: {BucketName}, Route: {Route}, File: {FileName}", bucketName, route, fileName);
|
||||
logger.LogError(exception, "Failed to transfer file to S3. Bucket: {BucketName}, keyName: {keyName}", bucketName, keyName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user