chore: group .NET into backend/ and drop non-.NET test artifacts
- Move all .NET (6 projects, solution, Directory.*.props, nuget.config) into backend/ so the monorepo root can host non-.NET projects later - Remove throwaway test artifacts: player.html, pl.json - Trim dead Flutter rules from .gitignore Build from backend/Musify.slnx: 0 warnings, 0 errors. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+73
@@ -0,0 +1,73 @@
|
||||
using MassTransit;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Musify.Application.Contracts;
|
||||
using Musify.Domain.Entities;
|
||||
using Musify.Domain.ValueObjects;
|
||||
using Musify.Infrastructure.MassTransit.Arguments;
|
||||
|
||||
namespace Musify.Infrastructure.MassTransit.Activities
|
||||
{
|
||||
internal class GenerateAudioWorkflowPathsActivity(
|
||||
IDatabase database,
|
||||
ILogger<GenerateAudioWorkflowPathsActivity> logger)
|
||||
: IExecuteActivity<GenerateAudioWorkflowPathsArguments>
|
||||
{
|
||||
public const string ExecuteEndpointName = "generate-audio-workflow-paths";
|
||||
|
||||
public async Task<ExecutionResult> Execute(ExecuteContext<GenerateAudioWorkflowPathsArguments> executeContext)
|
||||
{
|
||||
Track track;
|
||||
try
|
||||
{
|
||||
var getTrack = await database.Tracks.SingleOrDefaultAsync(p => p.Id == executeContext.Arguments.TrackId, executeContext.CancellationToken);
|
||||
track = getTrack ?? throw new InvalidOperationException($"Track with id {executeContext.Arguments.TrackId} not found.");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to retrieve track for TrackId {TrackId}",
|
||||
executeContext.Arguments.TrackId);
|
||||
throw;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
track.AudioTranscodeProcessingStatus = ProcessingStatus.Processing;
|
||||
var folderName = Guid.NewGuid().ToString();
|
||||
var sourceFileName = Path.GetFileName(executeContext.Arguments.SourceKey);
|
||||
var workingDirectory = Path.Combine(executeContext.Arguments.TemporaryRootDirectory, folderName);
|
||||
var sourceFilePath = Path.Combine(workingDirectory, sourceFileName);
|
||||
|
||||
Directory.CreateDirectory(workingDirectory);
|
||||
await database.SaveChangesAsync(executeContext.CancellationToken);
|
||||
|
||||
logger.LogDebug("Generated audio workflow paths in {WorkingDirectory}", workingDirectory);
|
||||
|
||||
return executeContext.CompletedWithVariables(new Dictionary<string, object>
|
||||
{
|
||||
[RoutingSlipVariableNames.Workflow.TemporalDirectory] = workingDirectory,
|
||||
[RoutingSlipVariableNames.Audio.SourceFilePath] = sourceFilePath,
|
||||
[RoutingSlipVariableNames.Audio.TranscodedDirectory] = workingDirectory
|
||||
} );
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to generate audio workflow paths for {SourceKey}",
|
||||
executeContext.Arguments.SourceKey);
|
||||
|
||||
try
|
||||
{
|
||||
track.AudioTranscodeProcessingStatus = ProcessingStatus.Failed;
|
||||
await database.SaveChangesAsync(executeContext.CancellationToken);
|
||||
}
|
||||
catch (Exception dbException)
|
||||
{
|
||||
logger.LogError(dbException, "Failed to update ProcessingStatus to Failed for track {TrackId}",
|
||||
executeContext.Arguments.TrackId);
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using MassTransit;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Musify.Application.Contracts;
|
||||
using Musify.Domain.Entities;
|
||||
using Musify.Domain.ValueObjects;
|
||||
using Musify.Infrastructure.MassTransit.Arguments;
|
||||
using Musify.Infrastructure.MassTransit.Logs;
|
||||
|
||||
namespace Musify.Infrastructure.MassTransit.Activities
|
||||
{
|
||||
internal class TranscodeAudioActivity(
|
||||
IDatabase database,
|
||||
IAudioTranscoderService audioTranscoder,
|
||||
ILogger<TranscodeAudioActivity> logger)
|
||||
: IActivity<TranscodeAudioArguments, TranscodeAudioLog>
|
||||
{
|
||||
public const string ExecuteEndpointName = "transcode-audio";
|
||||
|
||||
public async Task<ExecutionResult> Execute(ExecuteContext<TranscodeAudioArguments> executeContext)
|
||||
{
|
||||
var sourceFilePath = executeContext.GetVariable<string>(executeContext.Arguments.SourceFilePathVariable);
|
||||
ArgumentNullException.ThrowIfNull(sourceFilePath, nameof(sourceFilePath));
|
||||
var workingDirectory = executeContext.GetVariable<string>(executeContext.Arguments.WorkingDirectoryVariable);
|
||||
ArgumentNullException.ThrowIfNull(workingDirectory, nameof(workingDirectory));
|
||||
|
||||
Track track;
|
||||
try
|
||||
{
|
||||
var getTrack = await database.Tracks.SingleOrDefaultAsync(t => t.Id == executeContext.Arguments.TrackId, executeContext.CancellationToken);
|
||||
track = getTrack ?? throw new InvalidOperationException($"Track with Id {executeContext.Arguments.TrackId} not found");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to retrieve track with Id {TrackId} from database", executeContext.Arguments.TrackId);
|
||||
throw;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await using (var fileStream = File.OpenRead(sourceFilePath))
|
||||
{
|
||||
await audioTranscoder.TranscodeToAudioFileAsync(
|
||||
fileStream,
|
||||
workingDirectory,
|
||||
executeContext.CancellationToken);
|
||||
}
|
||||
|
||||
File.Delete(sourceFilePath);
|
||||
return executeContext.Completed();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to transcode {SourceFilePath}", sourceFilePath);
|
||||
|
||||
try
|
||||
{
|
||||
track.AudioTranscodeProcessingStatus = ProcessingStatus.Failed;
|
||||
await database.SaveChangesAsync(executeContext.CancellationToken);
|
||||
}
|
||||
catch (Exception dbException)
|
||||
{
|
||||
logger.LogError(dbException, "Failed to update ProcessingStatus to Failed for track {TrackId}",
|
||||
executeContext.Arguments.TrackId);
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public Task<CompensationResult> Compensate(CompensateContext<TranscodeAudioLog> compensateContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Directory.Exists(compensateContext.Log.WorkingDirectory))
|
||||
Directory.Delete(compensateContext.Log.WorkingDirectory, recursive: true);
|
||||
else
|
||||
logger.LogWarning("Working directory {WorkingDirectory} not found during compensation",
|
||||
compensateContext.Log.WorkingDirectory);
|
||||
return Task.FromResult(compensateContext.Compensated());
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to compensate transcoded audio directory {WorkingDirectory}", compensateContext.Log.WorkingDirectory);
|
||||
return Task.FromResult(compensateContext.Failed(exception));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
using MassTransit;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Musify.Application.Contracts;
|
||||
using Musify.Domain.Entities;
|
||||
using Musify.Domain.ValueObjects;
|
||||
using Musify.Infrastructure.MassTransit.Arguments;
|
||||
using Musify.Infrastructure.MassTransit.Logs;
|
||||
|
||||
namespace Musify.Infrastructure.MassTransit.Activities.Audio
|
||||
{
|
||||
internal class UpdateTrackAudioActivity(
|
||||
IDatabase database,
|
||||
ILogger<UpdateTrackAudioActivity> logger)
|
||||
: IActivity<UpdateTrackAudioArguments, UpdateTrackAudioLog>
|
||||
{
|
||||
public const string ExecuteEndpointName = "update-track-audio";
|
||||
|
||||
public async Task<ExecutionResult> Execute(ExecuteContext<UpdateTrackAudioArguments> executeContext)
|
||||
{
|
||||
Track track;
|
||||
try
|
||||
{
|
||||
var getTrack = await database.Tracks.SingleOrDefaultAsync(t => t.Id == executeContext.Arguments.TrackId, executeContext.CancellationToken);
|
||||
track = getTrack ?? throw new InvalidOperationException($"Track with id {executeContext.Arguments.TrackId} not found");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to retrieve track {TrackId}",
|
||||
executeContext.Arguments.TrackId);
|
||||
throw;
|
||||
}
|
||||
|
||||
var audioFolderKey = executeContext.Arguments.AudioFolderKey;
|
||||
logger.LogDebug("Resolved audio folder key: {AudioFolderKey}", audioFolderKey);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(audioFolderKey))
|
||||
{
|
||||
logger.LogWarning("Audio folder key is empty for track {TrackId}; skipping update", track.Id);
|
||||
return executeContext.Completed();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var log = new UpdateTrackAudioLog(
|
||||
track.Id,
|
||||
track.AudioFolderName);
|
||||
|
||||
track.AudioFolderName = Path.GetFileName(audioFolderKey);
|
||||
track.AudioTranscodeProcessingStatus = ProcessingStatus.Completed;
|
||||
await database.SaveChangesAsync(executeContext.CancellationToken);
|
||||
|
||||
logger.LogInformation("Updated track {TrackId} audio", executeContext.Arguments.TrackId);
|
||||
|
||||
return executeContext.Completed(log);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to update track {TrackId} audio",
|
||||
executeContext.Arguments.TrackId);
|
||||
|
||||
try
|
||||
{
|
||||
track.AudioTranscodeProcessingStatus = ProcessingStatus.Failed;
|
||||
await database.SaveChangesAsync(executeContext.CancellationToken);
|
||||
}
|
||||
catch (Exception dbException)
|
||||
{
|
||||
logger.LogError(dbException, "Failed to update ProcessingStatus to Failed for track {TrackId}",
|
||||
executeContext.Arguments.TrackId);
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<CompensationResult> Compensate(CompensateContext<UpdateTrackAudioLog> compensateContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
var track = await database.Tracks.SingleOrDefaultAsync(t => t.Id == compensateContext.Log.TrackId, compensateContext.CancellationToken);
|
||||
if (track is null)
|
||||
throw new InvalidOperationException($"Track with id {compensateContext.Log.TrackId} not found");
|
||||
|
||||
track.AudioFolderName = compensateContext.Log.PreviousAudioFolderName;
|
||||
track.AudioTranscodeProcessingStatus = ProcessingStatus.Failed;
|
||||
await database.SaveChangesAsync(compensateContext.CancellationToken);
|
||||
|
||||
logger.LogInformation("Compensated track {TrackId} audio", compensateContext.Log.TrackId);
|
||||
|
||||
return compensateContext.Compensated();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to compensate track {TrackId} audio",
|
||||
compensateContext.Log.TrackId);
|
||||
return compensateContext.Failed(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user