Changes on messages

This commit is contained in:
2026-03-28 21:26:45 +01:00
parent 4fa341d2c8
commit 2518101a52
25 changed files with 153 additions and 179 deletions
@@ -1,4 +1,4 @@
using Ardalis.Result; using Ardalis.Result;
using DispatchR.Abstractions.Send; using DispatchR.Abstractions.Send;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@@ -22,8 +22,8 @@ namespace Musify.Application.PlayLists.Handlers
var userExists = await database.Users.AnyAsync(u => u.Id == request.UserId, cancellationToken); var userExists = await database.Users.AnyAsync(u => u.Id == request.UserId, cancellationToken);
if (!userExists) if (!userExists)
{ {
logger.LogWarning("User with Id={UserId} does not exist.", request.UserId); logger.LogWarning("User {UserId} not found", request.UserId);
return Result.NotFound($"User with Id {request.UserId} does not exist."); return Result.NotFound($"User {request.UserId} not found");
} }
var playListEntity = CreatePlayListCommand.ToEntity(request, var playListEntity = CreatePlayListCommand.ToEntity(request,
@@ -54,11 +54,11 @@ namespace Musify.Application.PlayLists.Handlers
catch (Exception exception) catch (Exception exception)
{ {
await RollbackPicture(playListEntity, cancellationToken); await RollbackPicture(playListEntity, cancellationToken);
logger.LogError(exception, "Failed to create PlayList for user with id={UserId}.", request.UserId); logger.LogError(exception, "Failed to create playlist for user {UserId}", request.UserId);
return Result.Error($"Failed to create PlayList for user with id {request.UserId}."); return Result.Error($"Failed to create playlist for user {request.UserId}");
} }
logger.LogInformation("PlayList with id={PlayListId} created successfully for user with id={UserId}.", playListEntity.Id, request.UserId); logger.LogInformation("Created playlist {PlayListId} for user {UserId}", playListEntity.Id, request.UserId);
return Result.Created(PlayListResponse.FromEntity(playListEntity)); return Result.Created(PlayListResponse.FromEntity(playListEntity));
} }
@@ -71,7 +71,7 @@ namespace Musify.Application.PlayLists.Handlers
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Failed to rollback picture upload for PlayList with Id={PlayListId}.", playList.Id); logger.LogError(exception, "Failed to rollback picture upload for playlist {PlayListId}", playList.Id);
} }
} }
@@ -83,7 +83,7 @@ namespace Musify.Application.PlayLists.Handlers
var uploadResult = await storageHandler.UploadFileAsync(picture.FileStream, picture.ContentType, storageConfiguration.BucketName, pictureKey, cancellationToken); var uploadResult = await storageHandler.UploadFileAsync(picture.FileStream, picture.ContentType, storageConfiguration.BucketName, pictureKey, cancellationToken);
if (!uploadResult.IsSuccess) if (!uploadResult.IsSuccess)
{ {
logger.LogError("Failed to upload picture for PlayList with Id={PlayListId} to storage. Storage handler returned error={ErrorMessage}.", logger.LogError("Failed to upload picture for playlist {PlayListId} to storage: {ErrorMessage}",
playList.Id, string.Join(", ", uploadResult.Errors)); playList.Id, string.Join(", ", uploadResult.Errors));
return uploadResult.ToErrorResult(); return uploadResult.ToErrorResult();
} }
@@ -118,8 +118,8 @@ namespace Musify.Application.PlayLists.Handlers
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Failed to publish UpdatePlayListPictureEvent for PlayList with Id={PlayListId}.", playList.Id); logger.LogError(exception, "Failed to publish playlist picture update event for playlist {PlayListId}", playList.Id);
return Result.Error($"Failed to publish UpdatePlayListPictureEvent for PlayList with Id {playList.Id}."); return Result.Error($"Failed to publish playlist {playList.Id} picture update event");
} }
} }
} }
@@ -1,4 +1,4 @@
using Ardalis.Result; using Ardalis.Result;
using DispatchR.Abstractions.Send; using DispatchR.Abstractions.Send;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Musify.Application.Configuration; using Musify.Application.Configuration;
@@ -19,13 +19,13 @@ namespace Musify.Application.PlayLists.Handlers
cancellationToken); cancellationToken);
if (playList is null) if (playList is null)
{ {
logger.LogDebug("PlayList with id={PlayListId} not found", request.PlayListId); logger.LogDebug("Playlist {PlayListId} not found", request.PlayListId);
return Result.NotFound(); return Result.NotFound();
} }
if (playList.UserId != request.UserId) if (playList.UserId != request.UserId)
{ {
logger.LogInformation("PlayList with id={PlayListId} does not belong to user with id={UserId}", request.PlayListId, request.UserId); logger.LogWarning("Playlist {PlayListId} does not belong to user {UserId}", request.PlayListId, request.UserId);
return Result.Unauthorized(); return Result.Unauthorized();
} }
@@ -56,8 +56,8 @@ namespace Musify.Application.PlayLists.Handlers
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Failed to publish remove file event for PlayList id={PlayListId} and key={Key}.", playListId, key); logger.LogError(exception, "Failed to publish remove file event for playlist {PlayListId} with key {Key}", playListId, key);
return Result.Error($"Failed to publish remove file event for PlayList with id {playListId}."); return Result.Error($"Failed to publish remove file event for playlist {playListId}");
} }
} }
} }
@@ -1,4 +1,4 @@
using Ardalis.Result; using Ardalis.Result;
using DispatchR.Abstractions.Send; using DispatchR.Abstractions.Send;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Musify.Application.Contracts.Infrastructure; using Musify.Application.Contracts.Infrastructure;
@@ -18,7 +18,7 @@ namespace Musify.Application.PlayLists.Handlers
return playList is not null return playList is not null
? Result.Success(PlayListResponse.FromEntity(playList)) ? Result.Success(PlayListResponse.FromEntity(playList))
: Result.NotFound("Playlist not found."); : Result.NotFound("Playlist not found");
} }
} }
} }
@@ -1,4 +1,4 @@
using Ardalis.Result; using Ardalis.Result;
using DispatchR.Abstractions.Send; using DispatchR.Abstractions.Send;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Musify.Application.Configuration; using Musify.Application.Configuration;
@@ -24,13 +24,13 @@ namespace Musify.Application.PlayLists.Handlers
cancellationToken); cancellationToken);
if (playListEntity is null) if (playListEntity is null)
{ {
logger.LogInformation("PlayList with id={PlayListId} not found.", request.PlayListId); logger.LogInformation("Playlist {PlayListId} not found", request.PlayListId);
return Result.NotFound(); return Result.NotFound();
} }
if (playListEntity.UserId != request.UserId) if (playListEntity.UserId != request.UserId)
{ {
logger.LogWarning("User with id={UserId} is not the owner of the PlayList with id={PlayListId}.", request.UserId, request.PlayListId); logger.LogWarning("User {UserId} is not the owner of playlist {PlayListId}", request.UserId, request.PlayListId);
return Result.Unauthorized(); return Result.Unauthorized();
} }
@@ -50,11 +50,11 @@ namespace Musify.Application.PlayLists.Handlers
catch (Exception exception) catch (Exception exception)
{ {
await Rollback(updatePictureResult.Value, cancellationToken); await Rollback(updatePictureResult.Value, cancellationToken);
logger.LogError(exception, "Failed to update PlayList with id={PlayListId}.", playListEntity.Id); logger.LogError(exception, "Failed to update playlist {PlayListId}", playListEntity.Id);
return Result.Error($"Failed to update PlayList with id {playListEntity.Id}."); return Result.Error($"Failed to update playlist {playListEntity.Id}");
} }
logger.LogInformation("Successfully updated PlayList with id={PlayListId}.", playListEntity.Id); logger.LogInformation("Updated playlist {PlayListId}", playListEntity.Id);
return Result.Success(PlayListResponse.FromEntity(playListEntity)); return Result.Success(PlayListResponse.FromEntity(playListEntity));
} }
@@ -89,9 +89,9 @@ namespace Musify.Application.PlayLists.Handlers
if (!uploadResult.IsSuccess) if (!uploadResult.IsSuccess)
{ {
logger.LogError("Failed to upload picture for PlayList with Id={PlayListId} to storage. Storage handler returned error?={ErrorMessage}", logger.LogError("Failed to upload picture for playlist {PlayListId} to storage: {ErrorMessage}",
playList.Id, string.Join("; ", uploadResult.Errors)); playList.Id, string.Join("; ", uploadResult.Errors));
return Result.Error($"Failed to upload picture for PlayList with Id {playList.Id} to storage."); return Result.Error($"Failed to upload playlist {playList.Id} picture");
} }
playList.OriginalPictureName = pictureName; playList.OriginalPictureName = pictureName;
return Result.Success(pictureKey); return Result.Success(pictureKey);
@@ -122,8 +122,8 @@ namespace Musify.Application.PlayLists.Handlers
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Failed to publish UpdatePlayListPictureEvent for PlayList with id={PlayListId}.", playList.Id); logger.LogError(exception, "Failed to publish playlist picture update event for playlist {PlayListId}", playList.Id);
return Result.Error($"Failed to publish UpdatePlayListPictureEvent for PlayList with id {playList.Id}."); return Result.Error($"Failed to publish playlist {playList.Id} picture update event");
} }
} }
@@ -152,7 +152,7 @@ namespace Musify.Application.PlayLists.Handlers
storageConfiguration.BucketName, storageConfiguration.BucketName,
pictureKey, pictureKey,
cancellationToken); cancellationToken);
logger.LogInformation("Rolled back uploaded picture with key={PictureKey} from storage.", pictureKey); logger.LogInformation("Rolled back uploaded picture {PictureKey} from storage", pictureKey);
} }
async Task<Result> PublishRemoveFileEvent(string key, CancellationToken cancellationToken) async Task<Result> PublishRemoveFileEvent(string key, CancellationToken cancellationToken)
@@ -166,8 +166,8 @@ namespace Musify.Application.PlayLists.Handlers
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Failed to publish remove file event for key={Key}.", key); logger.LogError(exception, "Failed to publish remove file event for key {Key}", key);
return Result.Error($"Failed to publish remove file event for key {key}."); return Result.Error($"Failed to publish remove file event for {key}");
} }
} }
} }
@@ -1,4 +1,4 @@
using Ardalis.Result; using Ardalis.Result;
using DispatchR.Abstractions.Send; using DispatchR.Abstractions.Send;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Musify.Application.Configuration; using Musify.Application.Configuration;
@@ -17,11 +17,10 @@ namespace Musify.Application.Tracks.Handler
public async Task<Result<TrackResponse>> Handle(CreateTrackCommand request, CancellationToken cancellationToken) public async Task<Result<TrackResponse>> Handle(CreateTrackCommand request, CancellationToken cancellationToken)
{ {
var userExists = await database.Users.FindAsync(request.UserId, cancellationToken); var userExists = await database.Users.FindAsync(request.UserId, cancellationToken);
if (userExists is null) if (userExists is null)
{ {
logger.LogWarning("User with id={UserId} not found.", request.UserId); logger.LogWarning("User {UserId} not found", request.UserId);
return Result.NotFound($"User with id {request.UserId} not found."); return Result.NotFound($"User {request.UserId} not found");
} }
var trackEntity = CreateTrackCommand.ToEntity( var trackEntity = CreateTrackCommand.ToEntity(
@@ -60,7 +59,7 @@ namespace Musify.Application.Tracks.Handler
if (!pictureUpload.IsSuccess) if (!pictureUpload.IsSuccess)
{ {
var errors = string.Join(", ", pictureUpload.Errors); var errors = string.Join(", ", pictureUpload.Errors);
return Result.Error($"Failed to upload picture for track {request.Title}. Errors: {errors}."); return Result.Error($"Failed to upload picture for {request.Title}");
} }
var audioUpload = await storageHandler.UploadFileAsync( var audioUpload = await storageHandler.UploadFileAsync(
@@ -74,7 +73,7 @@ namespace Musify.Application.Tracks.Handler
{ {
await RollbackFilesAsync(pictureKey, audioKey, cancellationToken); await RollbackFilesAsync(pictureKey, audioKey, cancellationToken);
var errors = string.Join(", ", audioUpload.Errors); var errors = string.Join(", ", audioUpload.Errors);
return Result.Error($"Failed to upload audio for track {request.Title}. Errors: {errors}."); return Result.Error($"Failed to upload audio for {request.Title}");
} }
return Result.Success(); return Result.Success();
@@ -84,7 +83,7 @@ namespace Musify.Application.Tracks.Handler
{ {
await storageHandler.RemoveFileAsync(storageConfiguration.BucketName, pictureKey, cancellationToken); await storageHandler.RemoveFileAsync(storageConfiguration.BucketName, pictureKey, cancellationToken);
await storageHandler.RemoveFileAsync(storageConfiguration.BucketName, audioKey, cancellationToken); await storageHandler.RemoveFileAsync(storageConfiguration.BucketName, audioKey, cancellationToken);
logger.LogInformation("Rolled back uploaded files={PictureKey}, {AudioKey}.", pictureKey, audioKey); logger.LogInformation("Rolled back uploaded files {PictureKey}, {AudioKey}", pictureKey, audioKey);
} }
async Task PublishUpdateEvent(Track track, CancellationToken cancellationToken) async Task PublishUpdateEvent(Track track, CancellationToken cancellationToken)
@@ -110,7 +109,7 @@ namespace Musify.Application.Tracks.Handler
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Failed to publish resize picture event for Track with id={TrackId}.", track.Id); logger.LogError(exception, "Failed to publish track picture update event for track {TrackId}", track.Id);
} }
} }
@@ -130,7 +129,7 @@ namespace Musify.Application.Tracks.Handler
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Failed to publish transcode audio event for Track with id={TrackId}.", track.Id); logger.LogError(exception, "Failed to publish track audio update event for track {TrackId}", track.Id);
} }
} }
} }
@@ -1,4 +1,4 @@
using Ardalis.Result; using Ardalis.Result;
using DispatchR.Abstractions.Send; using DispatchR.Abstractions.Send;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Musify.Application.Configuration; using Musify.Application.Configuration;
@@ -15,16 +15,15 @@ namespace Musify.Application.Tracks.Handler
public async Task<Result> Handle(DeleteTrackCommand request, CancellationToken cancellationToken) public async Task<Result> Handle(DeleteTrackCommand request, CancellationToken cancellationToken)
{ {
var track = await database.Tracks.FindAsync(request.TrackId, cancellationToken); var track = await database.Tracks.FindAsync(request.TrackId, cancellationToken);
if (track is null) if (track is null)
{ {
logger.LogInformation("Track with id={TrackId} not found.", request.TrackId); logger.LogInformation("Track {TrackId} not found", request.TrackId);
return Result.NotFound(); return Result.NotFound();
} }
if (track.Id != request.UserId) if (track.Id != request.UserId)
{ {
logger.LogInformation("User with id={UserId} is not the owner of track with id={TrackId}.", request.UserId, request.TrackId); logger.LogWarning("User {UserId} unauthorized to delete track {TrackId}", request.UserId, request.TrackId);
return Result.Unauthorized(); return Result.Unauthorized();
} }
@@ -63,7 +62,7 @@ namespace Musify.Application.Tracks.Handler
async Task RemoveFile(string path, CancellationToken cancellationToken) async Task RemoveFile(string path, CancellationToken cancellationToken)
{ {
await storageHandler.RemoveFileAsync(storageConfiguration.BucketName, path, cancellationToken); await storageHandler.RemoveFileAsync(storageConfiguration.BucketName, path, cancellationToken);
logger.LogDebug("File with path={Path} removed from storage.", path); logger.LogDebug("Removed file {Path} from storage", path);
} }
} }
} }
@@ -1,4 +1,4 @@
using Ardalis.Result; using Ardalis.Result;
using DispatchR.Abstractions.Send; using DispatchR.Abstractions.Send;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@@ -14,24 +14,24 @@ namespace Musify.Application.Users.Handlers
public async Task<Result<UserResponse>> Handle(CreateUserCommand request, CancellationToken cancellationToken) public async Task<Result<UserResponse>> Handle(CreateUserCommand request, CancellationToken cancellationToken)
{ {
var userExists = await database.Users.AnyAsync(u => u.Id == request.Id, cancellationToken); var userExists = await database.Users.AnyAsync(u => u.Id == request.Id, cancellationToken);
if (!userExists) if (userExists)
{ {
logger.LogInformation("User with Id={UserId} already exists.", request.Id); logger.LogInformation("User {UserId} already exists", request.Id);
return Result<UserResponse>.Conflict($"A user with Id {request.Id} already exists."); return Result<UserResponse>.Conflict($"User {request.Id} already exists");
} }
var keycloakUser = await keycloakUserClient.GetUserByIdAsync(request.Id.ToString(), cancellationToken); var keycloakUser = await keycloakUserClient.GetUserByIdAsync(request.Id.ToString(), cancellationToken);
if (!keycloakUser.IsSuccess) if (!keycloakUser.IsSuccess)
{ {
logger.LogWarning("Keycloak user with Id={UserId} was not found.", request.Id); logger.LogWarning("Keycloak user {UserId} not found", request.Id);
return Result.NotFound("Keycloak user not found."); return Result.NotFound("Keycloak user not found");
} }
var newUser = CreateUserCommand.ToEntity(request); var newUser = CreateUserCommand.ToEntity(request);
await database.Users.AddAsync(newUser, cancellationToken); await database.Users.AddAsync(newUser, cancellationToken);
await database.SaveChangesAsync(cancellationToken); await database.SaveChangesAsync(cancellationToken);
logger.LogInformation("User with Id={UserId} created successfully.", newUser.Id); logger.LogInformation("Created user {UserId}", newUser.Id);
return Result.Created(new UserResponse( return Result.Created(new UserResponse(
newUser.Id.ToString(), newUser.Id.ToString(),
keycloakUser.Value.Name, keycloakUser.Value.Name,
@@ -10,7 +10,6 @@ namespace Musify.Application.Users.Commands
public async Task<Result> Handle(DeleteUserCommand request, CancellationToken cancellationToken) public async Task<Result> Handle(DeleteUserCommand request, CancellationToken cancellationToken)
{ {
var existingUser = await database.Users.FindAsync(request.Id, cancellationToken); var existingUser = await database.Users.FindAsync(request.Id, cancellationToken);
if (existingUser is null) if (existingUser is null)
return Result.NotFound(); return Result.NotFound();
@@ -1,4 +1,4 @@
using Ardalis.Result; using Ardalis.Result;
using DispatchR.Abstractions.Send; using DispatchR.Abstractions.Send;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Musify.Application.Contracts.Infrastructure; using Musify.Application.Contracts.Infrastructure;
@@ -15,14 +15,12 @@ namespace Musify.Application.Users.Handlers
var user = await database.Users var user = await database.Users
.AsNoTracking() .AsNoTracking()
.SingleOrDefaultAsync(u => u.Id == request.Id, cancellationToken); .SingleOrDefaultAsync(u => u.Id == request.Id, cancellationToken);
if (user is null) if (user is null)
return Result.NotFound("User not found."); return Result.NotFound("User not found");
var keycloakUser = await keycloakUserClient.GetUserByIdAsync(user.Id.ToString(), cancellationToken); var keycloakUser = await keycloakUserClient.GetUserByIdAsync(user.Id.ToString(), cancellationToken);
if (!keycloakUser.IsSuccess) if (!keycloakUser.IsSuccess)
return Result.NotFound("Keycloak user not found."); return Result.NotFound("Keycloak user not found");
return Result.Success(new UserResponse( return Result.Success(new UserResponse(
user.Id.ToString(), user.Id.ToString(),
@@ -15,14 +15,12 @@ namespace Musify.Application.Users.Handlers
var user = await database.Users var user = await database.Users
.AsNoTracking() .AsNoTracking()
.SingleOrDefaultAsync(u => u.Id == request.Id, cancellationToken); .SingleOrDefaultAsync(u => u.Id == request.Id, cancellationToken);
if (user is null) if (user is null)
return Result.NotFound("User not found."); return Result.NotFound("User not found");
var keycloakUser = await keycloakUserClient.GetUserByIdAsync(user.Id.ToString(), cancellationToken); var keycloakUser = await keycloakUserClient.GetUserByIdAsync(user.Id.ToString(), cancellationToken);
if (!keycloakUser.IsSuccess) if (!keycloakUser.IsSuccess)
return Result.NotFound("Keycloak user not found."); return Result.NotFound("Keycloak user not found");
return Result.Success(new UserResponse( return Result.Success(new UserResponse(
user.Id.ToString(), user.Id.ToString(),
+22 -40
View File
@@ -1,4 +1,4 @@
using Ardalis.Result; using Ardalis.Result;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Musify.Application.Contracts.Infrastructure; using Musify.Application.Contracts.Infrastructure;
using Musify.Infrastructure.Configuration; using Musify.Infrastructure.Configuration;
@@ -17,11 +17,7 @@ namespace Musify.Infrastructure.Audio
{ {
Directory.CreateDirectory(destinationPath); Directory.CreateDirectory(destinationPath);
logger.LogInformation( logger.LogInformation("Starting audio transcoding to DASH for {DestinationPath}", destinationPath);
"Starting audio transcoding to DASH. DestinationPath={DestinationPath}, Timeout={Timeout}, Executable={Executable}",
destinationPath,
audioTranscoderConfiguration.TranscodingTimeout,
audioTranscoderConfiguration.Ffmpeg.ExecutableName);
var executionResult = await ExecuteFfmpegWithInputAsync( var executionResult = await ExecuteFfmpegWithInputAsync(
BuildDashArguments(destinationPath, audioTranscoderConfiguration.Ffmpeg), BuildDashArguments(destinationPath, audioTranscoderConfiguration.Ffmpeg),
@@ -32,25 +28,22 @@ namespace Musify.Infrastructure.Audio
if (executionResult.ExitCode != 0) if (executionResult.ExitCode != 0)
{ {
logger.LogError( logger.LogError("Audio transcoding to DASH failed with exit code {ExitCode}. Output: {StandardOutput}, Error: {StandardError}",
"Audio transcoding to DASH format failed with exit code={ExitCode}. Standard Output={StandardOutput}, Standard Error={StandardError}", executionResult.ExitCode, executionResult.StandardOutput, executionResult.StandardError);
executionResult.ExitCode, return Result.Error($"Audio transcoding failed (ExitCode: {executionResult.ExitCode})");
executionResult.StandardOutput,
executionResult.StandardError);
return Result.Error($"Audio transcoding failed with exit code: {executionResult.ExitCode}. See logs for details.");
} }
logger.LogInformation("Audio transcoding to DASH format completed successfully. DestinationPath={DestinationPath}", destinationPath); logger.LogInformation("Audio transcoding to DASH completed for {DestinationPath}", destinationPath);
return Result.Success(); return Result.Success();
} }
catch (TimeoutException timeoutException) catch (TimeoutException timeoutException)
{ {
logger.LogError(timeoutException, "Audio transcoding timed out after={Timeout}. DestinationPath={DestinationPath}", audioTranscoderConfiguration.TranscodingTimeout, destinationPath); logger.LogError(timeoutException, "Audio transcoding timed out after {Timeout} for {DestinationPath}", audioTranscoderConfiguration.TranscodingTimeout, destinationPath);
return Result.Error("Audio transcoding timed out."); return Result.Error("Audio transcoding timed out");
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "An error occurred while transcoding audio to DASH format. DestinationPath={DestinationPath}", destinationPath); logger.LogError(exception, "Failed to transcode audio to DASH for {DestinationPath}", destinationPath);
return Result.Error(exception.Message); return Result.Error(exception.Message);
} }
} }
@@ -59,13 +52,13 @@ namespace Musify.Infrastructure.Audio
{ {
if (!File.Exists(filePath)) if (!File.Exists(filePath))
{ {
logger.LogWarning("Audio validation requested for a non-existing file. FilePath={FilePath}", filePath); logger.LogWarning("Audio validation requested for non-existing file {FilePath}", filePath);
return Result<bool>.Error($"Audio file not found: {filePath}"); return Result<bool>.Error($"Audio file not found: {filePath}");
} }
try try
{ {
logger.LogInformation("Starting audio file validation. FilePath={FilePath}, Timeout={Timeout}", filePath, audioTranscoderConfiguration.TranscodingTimeout); logger.LogDebug("Validating audio file {FilePath}", filePath);
var executionResult = await ExecuteFfmpegAsync( var executionResult = await ExecuteFfmpegAsync(
BuildValidateAudioArguments(filePath), BuildValidateAudioArguments(filePath),
@@ -76,26 +69,23 @@ namespace Musify.Infrastructure.Audio
var isValid = executionResult.ExitCode == 0; var isValid = executionResult.ExitCode == 0;
if (!isValid) if (!isValid)
{ {
logger.LogWarning( logger.LogWarning("Audio validation failed for {FilePath}: {StandardError}", filePath, executionResult.StandardError);
"Audio validation failed for file={FilePath}. Standard Error={StandardError}",
filePath,
executionResult.StandardError);
} }
else else
{ {
logger.LogInformation("Audio validation completed successfully. FilePath={FilePath}", filePath); logger.LogDebug("Audio validation successful for {FilePath}", filePath);
} }
return Result<bool>.Success(isValid); return Result<bool>.Success(isValid);
} }
catch (TimeoutException timeoutException) catch (TimeoutException timeoutException)
{ {
logger.LogError(timeoutException, "Audio validation timed out after={Timeout} for file={FilePath}.", audioTranscoderConfiguration.TranscodingTimeout, filePath); logger.LogError(timeoutException, "Audio validation timed out for {FilePath}", filePath);
return Result<bool>.Error("Audio validation timed out."); return Result<bool>.Error("Audio validation timed out.");
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "An error occurred while validating audio file={FilePath}.", filePath); logger.LogError(exception, "Failed to validate audio file {FilePath}", filePath);
return Result<bool>.Error(exception.Message); return Result<bool>.Error(exception.Message);
} }
} }
@@ -110,7 +100,7 @@ namespace Musify.Infrastructure.Audio
using var process = BuildProcess(arguments, workingDirectory, redirectStandardInput: true); using var process = BuildProcess(arguments, workingDirectory, redirectStandardInput: true);
process.Start(); process.Start();
logger.LogDebug("[{Operation}] ffmpeg process started. ProcessId={ProcessId}, WorkingDirectory={WorkingDirectory}", operationName, process.Id, workingDirectory); logger.LogDebug("[{Operation}] ffmpeg started (PID: {ProcessId}) in {WorkingDirectory}", operationName, process.Id, workingDirectory);
if (inputStream.CanSeek) if (inputStream.CanSeek)
inputStream.Position = 0; inputStream.Position = 0;
@@ -130,7 +120,7 @@ namespace Musify.Infrastructure.Audio
using var process = BuildProcess(arguments, workingDirectory, redirectStandardInput: false); using var process = BuildProcess(arguments, workingDirectory, redirectStandardInput: false);
process.Start(); process.Start();
logger.LogDebug("[{Operation}] ffmpeg process started. ProcessId={ProcessId}, WorkingDirectory={WorkingDirectory}", operationName, process.Id, workingDirectory); logger.LogDebug("[{Operation}] ffmpeg started (PID: {ProcessId}) in {WorkingDirectory}", operationName, process.Id, workingDirectory);
return await WaitForProcessResultAsync(process, operationName, cancellationToken); return await WaitForProcessResultAsync(process, operationName, cancellationToken);
} }
@@ -168,11 +158,8 @@ namespace Musify.Infrastructure.Audio
} }
catch (OperationCanceledException) when (!cancellationToken.IsCancellationRequested) catch (OperationCanceledException) when (!cancellationToken.IsCancellationRequested)
{ {
logger.LogError( logger.LogError("[{Operation}] ffmpeg timed out after {Timeout} (PID: {ProcessId})",
"[{Operation}] ffmpeg timed out after={Timeout}. ProcessId={ProcessId}", operationName, audioTranscoderConfiguration.TranscodingTimeout, process.Id);
operationName,
audioTranscoderConfiguration.TranscodingTimeout,
process.Id);
TryKillProcess(process); TryKillProcess(process);
throw new TimeoutException($"ffmpeg execution exceeded timeout {audioTranscoderConfiguration.TranscodingTimeout}."); throw new TimeoutException($"ffmpeg execution exceeded timeout {audioTranscoderConfiguration.TranscodingTimeout}.");
@@ -181,13 +168,8 @@ namespace Musify.Infrastructure.Audio
var standardError = await errorTask; var standardError = await errorTask;
var standardOutput = await outputTask; var standardOutput = await outputTask;
logger.LogDebug( logger.LogDebug("[{Operation}] ffmpeg finished (PID: {ProcessId}). Exit code: {ExitCode}, Output: {OutputLength}B, Error: {ErrorLength}B",
"[{Operation}] ffmpeg finished. ProcessId={ProcessId}, ExitCode={ExitCode}, StdOutLength={StdOutLength}, StdErrLength={StdErrLength}", operationName, process.Id, process.ExitCode, standardOutput.Length, standardError.Length);
operationName,
process.Id,
process.ExitCode,
standardOutput.Length,
standardError.Length);
return new FfmpegExecutionResult(process.ExitCode, standardOutput, standardError); return new FfmpegExecutionResult(process.ExitCode, standardOutput, standardError);
} }
@@ -201,7 +183,7 @@ namespace Musify.Infrastructure.Audio
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Failed to kill ffmpeg process. ProcessId={ProcessId}", process.Id); logger.LogError(exception, "Failed to kill ffmpeg process (PID: {ProcessId})", process.Id);
} }
} }
@@ -1,4 +1,4 @@
using Ardalis.Result; using Ardalis.Result;
using Keycloak.Net; using Keycloak.Net;
using Keycloak.Net.Models.Users; using Keycloak.Net.Models.Users;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@@ -23,12 +23,12 @@ namespace Musify.Infrastructure.Identity
} }
catch (OperationCanceledException) catch (OperationCanceledException)
{ {
logger.LogError("Operation to retrieve Keycloak user with id={KeycloakId} was cancelled.", keycloakId); logger.LogWarning("Operation to retrieve Keycloak user {KeycloakId} was cancelled", keycloakId);
return Result.Error("Operation was cancelled."); return Result.Error("Operation cancelled");
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogWarning(exception, "Keycloak user with id={KeycloakId} could not be retrieved.", keycloakId); logger.LogWarning(exception, "Failed to retrieve Keycloak user {KeycloakId}", keycloakId);
return Result.NotFound(); return Result.NotFound();
} }
return Result.Success(KeycloakUserMapper.Map(keycloakUser)); return Result.Success(KeycloakUserMapper.Map(keycloakUser));
@@ -38,9 +38,8 @@ namespace Musify.Infrastructure.MassTransit.Activities
Directory.CreateDirectory(workingDirectory); Directory.CreateDirectory(workingDirectory);
logger.LogDebug("Generated audio workflow paths. WorkingDirectory={WorkingDirectory}, SourceFilePath={SourceFilePath}", logger.LogDebug("Generated audio workflow paths in {WorkingDirectory}",
workingDirectory, workingDirectory);
sourceFilePath);
await processTrackingStore.CompleteStepAsync(processId, stepId, executeContext.CancellationToken); await processTrackingStore.CompleteStepAsync(processId, stepId, executeContext.CancellationToken);
return executeContext.CompletedWithVariables(new Dictionary<string, object> return executeContext.CompletedWithVariables(new Dictionary<string, object>
@@ -53,7 +52,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Error generating audio workflow paths for key={SourceKey}", logger.LogError(exception, "Failed to generate audio workflow paths for {SourceKey}",
executeContext.Arguments.SourceKey); executeContext.Arguments.SourceKey);
await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken); await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken);
throw; throw;
@@ -1,4 +1,4 @@
using MassTransit; using MassTransit;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Musify.Application.Contracts.Infrastructure; using Musify.Application.Contracts.Infrastructure;
using Musify.Domain.Entities; using Musify.Domain.Entities;
@@ -48,7 +48,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
if (!result.IsSuccess) if (!result.IsSuccess)
{ {
var errorMessage = string.Join("; ", result.Errors); var errorMessage = string.Join("; ", result.Errors);
logger.LogError("Transcoding failed for file={SourceFilePath}. Errors={ErrorMessage}", logger.LogError("Transcoding failed for {SourceFilePath}: {Errors}",
sourceFilePath, errorMessage); sourceFilePath, errorMessage);
throw new Exception(errorMessage); throw new Exception(errorMessage);
} }
@@ -60,7 +60,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Error during transcoding activity for file={SourceFilePath}", logger.LogError(exception, "Failed to transcode {SourceFilePath}",
sourceFilePath); sourceFilePath);
await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken); await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken);
throw; throw;
@@ -74,13 +74,13 @@ namespace Musify.Infrastructure.MassTransit.Activities
if (Directory.Exists(compensateContext.Log.WorkingDirectory)) if (Directory.Exists(compensateContext.Log.WorkingDirectory))
Directory.Delete(compensateContext.Log.WorkingDirectory, recursive: true); Directory.Delete(compensateContext.Log.WorkingDirectory, recursive: true);
else else
logger.LogWarning("Working directory={WorkingDirectory} does not exist during compensation", logger.LogWarning("Working directory {WorkingDirectory} not found during compensation",
compensateContext.Log.WorkingDirectory); compensateContext.Log.WorkingDirectory);
return Task.FromResult(compensateContext.Compensated()); return Task.FromResult(compensateContext.Compensated());
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Error compensating transcoded audio directory={WorkingDirectory}", compensateContext.Log.WorkingDirectory); logger.LogError(exception, "Failed to compensate transcoded audio directory {WorkingDirectory}", compensateContext.Log.WorkingDirectory);
return Task.FromResult(compensateContext.Failed(exception)); return Task.FromResult(compensateContext.Failed(exception));
} }
} }
@@ -1,4 +1,4 @@
using MassTransit; using MassTransit;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Musify.Application.Contracts.Infrastructure; using Musify.Application.Contracts.Infrastructure;
using Musify.Domain.Entities; using Musify.Domain.Entities;
@@ -39,7 +39,7 @@ namespace Musify.Infrastructure.MassTransit.Activities.Audio
if (track is null) if (track is null)
{ {
logger.LogWarning("Track with id={TrackId} not found", logger.LogWarning("Track {TrackId} not found",
executeContext.Arguments.TrackId); executeContext.Arguments.TrackId);
throw new InvalidOperationException($"Track with id {executeContext.Arguments.TrackId} not found"); throw new InvalidOperationException($"Track with id {executeContext.Arguments.TrackId} not found");
} }
@@ -53,7 +53,7 @@ namespace Musify.Infrastructure.MassTransit.Activities.Audio
database.Tracks.Update(track); database.Tracks.Update(track);
await database.SaveChangesAsync(executeContext.CancellationToken); await database.SaveChangesAsync(executeContext.CancellationToken);
logger.LogInformation("Updated Track={TrackId} audio", logger.LogInformation("Updated track {TrackId} audio",
executeContext.Arguments.TrackId); executeContext.Arguments.TrackId);
await processTrackingStore.CompleteStepAsync(processId, stepId, executeContext.CancellationToken); await processTrackingStore.CompleteStepAsync(processId, stepId, executeContext.CancellationToken);
@@ -61,7 +61,7 @@ namespace Musify.Infrastructure.MassTransit.Activities.Audio
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Error updating Track={TrackId} audio", logger.LogError(exception, "Failed to update track {TrackId} audio",
executeContext.Arguments.TrackId); executeContext.Arguments.TrackId);
await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken); await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken);
throw; throw;
@@ -90,7 +90,7 @@ namespace Musify.Infrastructure.MassTransit.Activities.Audio
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Error compensating Track={TrackId} audio", compensateContext.Log.TrackId); logger.LogError(exception, "Failed to compensate track {TrackId} audio", compensateContext.Log.TrackId);
return compensateContext.Failed(exception); return compensateContext.Failed(exception);
} }
} }
@@ -1,4 +1,4 @@
using MassTransit; using MassTransit;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Musify.Application.Contracts.Infrastructure; using Musify.Application.Contracts.Infrastructure;
using Musify.Domain.Entities; using Musify.Domain.Entities;
@@ -44,7 +44,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
if (!getFile.IsSuccess) if (!getFile.IsSuccess)
{ {
var errorMessage = string.Join("; ", getFile.Errors); var errorMessage = string.Join("; ", getFile.Errors);
logger.LogWarning("Failed to download file from bucket. Bucket={Bucket}, Key={Key}, Errors={Errors}", logger.LogWarning("Failed to download {Bucket}/{Key}: {Errors}",
executeContext.Arguments.Bucket, executeContext.Arguments.Bucket,
executeContext.Arguments.Key, executeContext.Arguments.Key,
errorMessage); errorMessage);
@@ -70,7 +70,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Error downloading file from bucket"); logger.LogError(exception, "Failed to download file from bucket");
await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken); await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken);
throw; throw;
} }
@@ -85,7 +85,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Error compensating downloaded file={DestinationFilePath}", compensateContext.Log.DestinationFilePath); logger.LogError(exception, "Failed to compensate downloaded file {DestinationFilePath}", compensateContext.Log.DestinationFilePath);
return Task.FromResult(compensateContext.Failed(exception)); return Task.FromResult(compensateContext.Failed(exception));
} }
} }
@@ -1,4 +1,4 @@
using MassTransit; using MassTransit;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Musify.Application.Contracts.Infrastructure; using Musify.Application.Contracts.Infrastructure;
using Musify.Domain.Entities; using Musify.Domain.Entities;
@@ -40,7 +40,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
if (!removeFile.IsSuccess) if (!removeFile.IsSuccess)
{ {
var errorMessage = string.Join("; ", removeFile.Errors); var errorMessage = string.Join("; ", removeFile.Errors);
logger.LogWarning("Failed to remove file={Key} from bucket={Bucket}. Errors={Errors}", logger.LogWarning("Failed to remove {Key} from bucket {Bucket}: {Errors}",
executeContext.Arguments.Key, executeContext.Arguments.Key,
executeContext.Arguments.Bucket, executeContext.Arguments.Bucket,
errorMessage); errorMessage);
@@ -51,7 +51,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Error removing file={Key} from bucket={Bucket}", logger.LogError(exception, "Failed to remove {Key} from bucket {Bucket}",
executeContext.Arguments.Key, executeContext.Arguments.Key,
executeContext.Arguments.Bucket); executeContext.Arguments.Bucket);
await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken); await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken);
@@ -1,4 +1,4 @@
using MassTransit; using MassTransit;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Musify.Application.Contracts.Infrastructure; using Musify.Application.Contracts.Infrastructure;
using Musify.Domain.Entities; using Musify.Domain.Entities;
@@ -51,7 +51,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
if (!transferFilesResult.IsSuccess) if (!transferFilesResult.IsSuccess)
{ {
var errorMessage = string.Join("; ", transferFilesResult.Errors); var errorMessage = string.Join("; ", transferFilesResult.Errors);
logger.LogWarning("Failed to transfer files from={FolderPath} to bucket={DestinationBucket}, key={DestinationKey}. Errors={Errors}", logger.LogWarning("Failed to transfer files from {FolderPath} to {DestinationBucket}/{DestinationKey}: {Errors}",
folderPath, folderPath,
executeContext.Arguments.DestinationBucket, executeContext.Arguments.DestinationBucket,
destinationKey, destinationKey,
@@ -64,7 +64,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Error transferring files from={FolderPath} to bucket={DestinationBucket}", logger.LogError(exception, "Failed to transfer files from {FolderPath} to {DestinationBucket}",
folderPath, folderPath,
executeContext.Arguments.DestinationBucket); executeContext.Arguments.DestinationBucket);
await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken); await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken);
@@ -88,7 +88,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Error compensating transferred files to bucket={DestinationBucket}", compensateContext.Log.DestinationBucket); logger.LogError(exception, "Failed to compensate file transfers to {DestinationBucket}", compensateContext.Log.DestinationBucket);
return compensateContext.Failed(exception); return compensateContext.Failed(exception);
} }
} }
@@ -1,4 +1,4 @@
using MassTransit; using MassTransit;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using MimeMapping; using MimeMapping;
using Musify.Application.Contracts.Infrastructure; using Musify.Application.Contracts.Infrastructure;
@@ -46,7 +46,7 @@ namespace Musify.Infrastructure.MassTransit.Activities.Files
if (!uploadResult.IsSuccess) if (!uploadResult.IsSuccess)
{ {
var errors = string.Join("; ", uploadResult.Errors); var errors = string.Join("; ", uploadResult.Errors);
logger.LogWarning("Failed to upload file to bucket. Bucket={Bucket}, Key={Key}, Errors={Errors}", logger.LogWarning("Failed to upload file to bucket {Bucket}/{Route}: {Errors}",
executeContext.Arguments.DestinationBucket, executeContext.Arguments.DestinationBucket,
executeContext.Arguments.DestinationRoute, executeContext.Arguments.DestinationRoute,
errors); errors);
@@ -60,7 +60,7 @@ namespace Musify.Infrastructure.MassTransit.Activities.Files
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "An error occurred while uploading file to bucket for process={ProcessId} at step={StepId}", processId, stepId); logger.LogError(exception, "Failed to upload file to bucket for process {ProcessId} step {StepId}", processId, stepId);
await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken); await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken);
throw; throw;
} }
@@ -78,7 +78,8 @@ namespace Musify.Infrastructure.MassTransit.Activities.Files
if (!uploadResult.IsSuccess) if (!uploadResult.IsSuccess)
{ {
var errors = string.Join("; ", uploadResult.Errors); var errors = string.Join("; ", uploadResult.Errors);
logger.LogError($"Failed to remove file from bucket during compensation. Bucket={compensateContext.Log.DestinationBucket}, Key={compensateContext.Log.DestinationKey}, Errors={errors}"); logger.LogError("Failed to remove file from bucket during compensation. Bucket: {Bucket}, Key: {Key}, Errors: {Errors}",
compensateContext.Log.DestinationBucket, compensateContext.Log.DestinationKey, errors);
return compensateContext.Failed(new Exception($"Failed to remove file from bucket during compensation. Bucket: {compensateContext.Log.DestinationBucket}, Key: {compensateContext.Log.DestinationKey}, Errors: {errors}")); return compensateContext.Failed(new Exception($"Failed to remove file from bucket during compensation. Bucket: {compensateContext.Log.DestinationBucket}, Key: {compensateContext.Log.DestinationKey}, Errors: {errors}"));
} }
@@ -86,7 +87,7 @@ namespace Musify.Infrastructure.MassTransit.Activities.Files
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "An error occurred while compensating upload file to bucket activity for bucket={Bucket} and key={Key}", logger.LogError(exception, "Error compensating file upload for {Bucket}/{Key}",
compensateContext.Log.DestinationBucket, compensateContext.Log.DestinationBucket,
compensateContext.Log.DestinationKey); compensateContext.Log.DestinationKey);
return compensateContext.Failed(exception); return compensateContext.Failed(exception);
@@ -47,9 +47,8 @@ namespace Musify.Infrastructure.MassTransit.Activities
Directory.CreateDirectory(workingDirectory); Directory.CreateDirectory(workingDirectory);
logger.LogDebug("Generated picture workflow paths. WorkingDirectory={WorkingDirectory}, SourceFilePath={SourceFilePath}", logger.LogDebug("Generated picture workflow paths in {WorkingDirectory}",
workingDirectory, workingDirectory);
sourceFilePath);
await processTrackingStore.CompleteStepAsync(processId, stepId, executeContext.CancellationToken); await processTrackingStore.CompleteStepAsync(processId, stepId, executeContext.CancellationToken);
return executeContext.CompletedWithVariables(new Dictionary<string, object> return executeContext.CompletedWithVariables(new Dictionary<string, object>
@@ -64,7 +63,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Error generating picture workflow paths for key={SourceKey}", logger.LogError(exception, "Failed to generate picture workflow paths for {SourceKey}",
executeContext.Arguments.SourceKey); executeContext.Arguments.SourceKey);
await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken); await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken);
throw; throw;
@@ -1,4 +1,4 @@
using MassTransit; using MassTransit;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Musify.Application.Contracts.Infrastructure; using Musify.Application.Contracts.Infrastructure;
using Musify.Domain.Entities; using Musify.Domain.Entities;
@@ -41,7 +41,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
{ {
if (!File.Exists(sourceFilePath)) if (!File.Exists(sourceFilePath))
{ {
logger.LogWarning("Source file not found at={SourceFilePath}", sourceFilePath); logger.LogWarning("Source file not found: {SourceFilePath}", sourceFilePath);
throw new FileNotFoundException($"Source file not found: {sourceFilePath}"); throw new FileNotFoundException($"Source file not found: {sourceFilePath}");
} }
@@ -56,7 +56,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
if (!resizedPicture.IsSuccess) if (!resizedPicture.IsSuccess)
{ {
var errorMessage = string.Join("; ", resizedPicture.Errors); var errorMessage = string.Join("; ", resizedPicture.Errors);
logger.LogError("Failed to resize picture={SourceFilePath} to={Width}x{Height}. Errors={Errors}", logger.LogError("Failed to resize picture {SourceFilePath} to {Width}x{Height}: {Errors}",
sourceFilePath, sourceFilePath,
executeContext.Arguments.Width, executeContext.Arguments.Width,
executeContext.Arguments.Height, executeContext.Arguments.Height,
@@ -71,7 +71,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
await using var destinationStream = File.Create(destinationFilePath); await using var destinationStream = File.Create(destinationFilePath);
await resizedPicture.Value.CopyToAsync(destinationStream, executeContext.CancellationToken); await resizedPicture.Value.CopyToAsync(destinationStream, executeContext.CancellationToken);
logger.LogDebug("Picture resized from={SourceFilePath} to={DestinationFilePath}", logger.LogDebug("Resized picture from {SourceFilePath} to {DestinationFilePath}",
sourceFilePath, sourceFilePath,
destinationFilePath); destinationFilePath);
@@ -80,7 +80,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Error resizing picture={SourceFilePath}", sourceFilePath); logger.LogError(exception, "Failed to resize picture {SourceFilePath}", sourceFilePath);
await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken); await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken);
throw; throw;
} }
@@ -95,7 +95,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Error compensating resized file={DestinationFilePath}", compensateContext.Log.DestinationFilePath); logger.LogError(exception, "Failed to compensate resized file {DestinationFilePath}", compensateContext.Log.DestinationFilePath);
return Task.FromResult(compensateContext.Failed(exception)); return Task.FromResult(compensateContext.Failed(exception));
} }
} }
@@ -1,4 +1,4 @@
using MassTransit; using MassTransit;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Musify.Application.Contracts.Infrastructure; using Musify.Application.Contracts.Infrastructure;
using Musify.Domain.Entities; using Musify.Domain.Entities;
@@ -46,7 +46,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
if (playList is null) if (playList is null)
{ {
logger.LogWarning("PlayList with id={PlayListId} not found", logger.LogWarning("Playlist {PlayListId} not found",
executeContext.Arguments.PlayListId); executeContext.Arguments.PlayListId);
throw new InvalidOperationException($"PlayList with id {executeContext.Arguments.PlayListId} not found"); throw new InvalidOperationException($"PlayList with id {executeContext.Arguments.PlayListId} not found");
} }
@@ -66,7 +66,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
database.PlayLists.Update(playList); database.PlayLists.Update(playList);
await database.SaveChangesAsync(executeContext.CancellationToken); await database.SaveChangesAsync(executeContext.CancellationToken);
logger.LogInformation("Updated PlayList={PlayListId} pictures", logger.LogInformation("Updated playlist {PlayListId} pictures",
executeContext.Arguments.PlayListId); executeContext.Arguments.PlayListId);
await processTrackingStore.CompleteStepAsync(processId, stepId, executeContext.CancellationToken); await processTrackingStore.CompleteStepAsync(processId, stepId, executeContext.CancellationToken);
@@ -74,7 +74,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Error updating PlayList={PlayListId} pictures", logger.LogError(exception, "Failed to update playlist {PlayListId} pictures",
executeContext.Arguments.PlayListId); executeContext.Arguments.PlayListId);
await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken); await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken);
throw; throw;
@@ -106,7 +106,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Error compensating PlayList={PlayListId} pictures", compensateContext.Log.PlayListId); logger.LogError(exception, "Failed to compensate playlist {PlayListId} pictures", compensateContext.Log.PlayListId);
return compensateContext.Failed(exception); return compensateContext.Failed(exception);
} }
} }
@@ -1,4 +1,4 @@
using MassTransit; using MassTransit;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Musify.Application.Contracts.Infrastructure; using Musify.Application.Contracts.Infrastructure;
using Musify.Domain.Entities; using Musify.Domain.Entities;
@@ -46,7 +46,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
if (track is null) if (track is null)
{ {
logger.LogWarning("Track with id={TrackId} not found", logger.LogWarning("Track {TrackId} not found",
executeContext.Arguments.TrackId); executeContext.Arguments.TrackId);
throw new InvalidOperationException($"Track with id {executeContext.Arguments.TrackId} not found"); throw new InvalidOperationException($"Track with id {executeContext.Arguments.TrackId} not found");
} }
@@ -66,7 +66,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
database.Tracks.Update(track); database.Tracks.Update(track);
await database.SaveChangesAsync(executeContext.CancellationToken); await database.SaveChangesAsync(executeContext.CancellationToken);
logger.LogInformation("Updated Track={TrackId} pictures", logger.LogInformation("Updated track {TrackId} pictures",
executeContext.Arguments.TrackId); executeContext.Arguments.TrackId);
await processTrackingStore.CompleteStepAsync(processId, stepId, executeContext.CancellationToken); await processTrackingStore.CompleteStepAsync(processId, stepId, executeContext.CancellationToken);
@@ -74,7 +74,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Error updating Track={TrackId} pictures", logger.LogError(exception, "Failed to update track {TrackId} pictures",
executeContext.Arguments.TrackId); executeContext.Arguments.TrackId);
await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken); await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken);
throw; throw;
@@ -106,7 +106,7 @@ namespace Musify.Infrastructure.MassTransit.Activities
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Error compensating Track={TrackId} pictures", compensateContext.Log.TrackId); logger.LogError(exception, "Failed to compensate track {TrackId} pictures", compensateContext.Log.TrackId);
return compensateContext.Failed(exception); return compensateContext.Failed(exception);
} }
} }
+5 -5
View File
@@ -1,4 +1,4 @@
using Ardalis.Result; using Ardalis.Result;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Musify.Application.Contracts.Infrastructure; using Musify.Application.Contracts.Infrastructure;
using SixLabors.ImageSharp; using SixLabors.ImageSharp;
@@ -13,7 +13,7 @@ namespace Musify.Infrastructure.Pictures
{ {
try try
{ {
logger.LogDebug("Resizing picture to={Width}x{Height}", width, height); logger.LogDebug("Resizing picture to {Width}x{Height}", width, height);
if (pictureStream.CanSeek && pictureStream.Position > 0) if (pictureStream.CanSeek && pictureStream.Position > 0)
pictureStream.Position = 0; pictureStream.Position = 0;
@@ -31,13 +31,13 @@ namespace Musify.Infrastructure.Pictures
memoryStream.Position = 0; memoryStream.Position = 0;
logger.LogDebug("Picture resized successfully. OutputLength={Length}", memoryStream.Length); logger.LogDebug("Picture resized to {Width}x{Height}, length: {Length}", width, height, memoryStream.Length);
return Result<Stream>.Success(memoryStream); return Result<Stream>.Success(memoryStream);
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "An error occurred while resizing the picture to={Width}x{Height}.", width, height); logger.LogError(exception, "Failed to resize picture to {Width}x{Height}", width, height);
return Result.Error("An error occurred while resizing the picture."); return Result.Error("Failed to resize picture");
} }
} }
} }
+19 -19
View File
@@ -1,4 +1,4 @@
using Amazon.S3; using Amazon.S3;
using Amazon.S3.Model; using Amazon.S3.Model;
using Amazon.S3.Transfer; using Amazon.S3.Transfer;
using Ardalis.Result; using Ardalis.Result;
@@ -21,19 +21,19 @@ namespace Musify.Infrastructure.Storage
Key = key, Key = key,
}; };
logger.LogDebug("Getting file from S3. Bucket={Bucket}, Key={Key}", bucket, key);
try try
{ {
var response = await amazonS3.GetObjectAsync(request, cancellationToken); var response = await amazonS3.GetObjectAsync(request, cancellationToken);
logger.LogDebug("Successfully got file from S3 with bucket={Bucket} and key={Key}", bucket, key); logger.LogDebug("Retrieved file from S3 {Bucket}/{Key}", bucket, key);
return Result.Success(response.ResponseStream); return Result.Success(response.ResponseStream);
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogWarning(exception, "Failed to get file from S3. Bucket={Bucket}, Key={Key}", bucket, key); logger.LogWarning(exception, "Failed to get file from S3 {Bucket}/{Key}", bucket, key);
return Result.NotFound($"File not found in S3 with bucket: {bucket} and key: {key}"); return Result.NotFound($"File {bucket}/{key} not found");
} }
} }
@@ -47,7 +47,7 @@ namespace Musify.Infrastructure.Storage
Protocol = storageClientConfiguration.UseHttp ? Protocol.HTTP : Protocol.HTTPS Protocol = storageClientConfiguration.UseHttp ? Protocol.HTTP : Protocol.HTTPS
}; };
logger.LogDebug("Getting pre-signed URL from S3. Bucket={BucketName}, Key={Key}, Expires={Expires}", bucket, key, request.Expires); logger.LogDebug("Generating pre-signed URL for {Bucket}/{Key}", bucket, key);
var url = await amazonS3.GetPreSignedURLAsync(request); var url = await amazonS3.GetPreSignedURLAsync(request);
return url; return url;
@@ -61,7 +61,7 @@ namespace Musify.Infrastructure.Storage
Key = key, Key = key,
}; };
logger.LogDebug("Removing file from S3. Bucket={Bucket}, Key={Key}", bucket, key); logger.LogDebug("Removing file from S3 {Bucket}/{Key}", bucket, key);
var response = await amazonS3.DeleteObjectAsync(request, cancellationToken); var response = await amazonS3.DeleteObjectAsync(request, cancellationToken);
return Result.NoContent(); return Result.NoContent();
@@ -96,18 +96,18 @@ namespace Musify.Infrastructure.Storage
await trasnsferUtility.UploadAsync(filePath, bucket, key, cancellationToken); await trasnsferUtility.UploadAsync(filePath, bucket, key, cancellationToken);
upload.State = UploadState.Successful; upload.State = UploadState.Successful;
successCount++; successCount++;
logger.LogDebug("Transferred file to S3. Bucket={Bucket}, Key={Key}", bucket, key); logger.LogDebug("Transferred file to S3 {Bucket}/{Key}", bucket, key);
} }
catch (Exception exception) catch (Exception exception)
{ {
failedCount++; failedCount++;
upload.State = UploadState.Failed; upload.State = UploadState.Failed;
logger.LogError(exception, "Failed to transfer file to S3. Bucket={Bucket}, key={key}", bucket, key); logger.LogError(exception, "Failed to transfer file to S3 {Bucket}/{Key}", bucket, key);
} }
} }
await database.SaveChangesAsync(cancellationToken); await database.SaveChangesAsync(cancellationToken);
logger.LogInformation("TransferFiles completed. Bucket={Bucket}, Route={Route}, Success={SuccessCount}, Failed={FailedCount}", bucket, route, successCount, failedCount); logger.LogInformation("File transfer completed to {Bucket}/{Route}. Success: {SuccessCount}, Failed: {FailedCount}", bucket, route, successCount, failedCount);
return Result.Success(); return Result.Success();
} }
@@ -122,8 +122,8 @@ namespace Musify.Infrastructure.Storage
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Failed to upload file to S3 with bucket={Bucket} and key={Key}", bucket, key); logger.LogError(exception, "Failed to upload file to S3 {Bucket}/{Key}", bucket, key);
return Result.Error($"Failed to upload file to S3 with bucket: {bucket} and key: {key}"); return Result.Error($"Failed to upload to {bucket}/{key}");
} }
} }
@@ -149,18 +149,18 @@ namespace Musify.Infrastructure.Storage
try try
{ {
var response = await amazonS3.PutObjectAsync(request, cancellationToken); var response = await amazonS3.PutObjectAsync(request, cancellationToken);
logger.LogDebug("Uploaded file to S3. Bucket?={Bucket}, Key={Key}", bucket, key); logger.LogDebug("Uploaded file to S3 {Bucket}/{Key}", bucket, key);
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Failed to upload file to S3 with bucket={Bucket} and key={Key}", bucket, key); logger.LogError(exception, "Failed to upload file to S3 {Bucket}/{Key}", bucket, key);
upload.State = UploadState.Failed; upload.State = UploadState.Failed;
return Result.Error($"Failed to upload file to S3 with bucket: {bucket} and key: {key}"); return Result.Error($"Failed to upload to {bucket}/{key}");
} }
upload.State = UploadState.Successful; upload.State = UploadState.Successful;
await database.SaveChangesAsync(cancellationToken); await database.SaveChangesAsync(cancellationToken);
logger.LogDebug("Saved upload record to database. Bucket={Bucket}, Key={Key}", bucket, key); logger.LogDebug("Saved upload record for {Bucket}/{Key}", bucket, key);
return Result.Success(key); return Result.Success(key);
} }
@@ -179,15 +179,15 @@ namespace Musify.Infrastructure.Storage
try try
{ {
var response = await amazonS3.CopyObjectAsync(request, cancellationToken); var response = await amazonS3.CopyObjectAsync(request, cancellationToken);
logger.LogInformation("Successfully copied file from S3 with bucket={SourceBucket} and key={SourceKey} to bucket={DestinationBucket} and key={DestinationKey}", logger.LogInformation("Copied file from {SourceBucket}/{SourceKey} to {DestinationBucket}/{DestinationKey}",
sourceBucket, sourceKey, destinationBucket, destinationKey); sourceBucket, sourceKey, destinationBucket, destinationKey);
return Result.Success(); return Result.Success();
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.LogError(exception, "Failed to copy file from S3 with bucket={SourceBucket} and key={SourceKey} to bucket={DestinationBucket} and key={DestinationKey}", logger.LogError(exception, "Failed to copy file from {SourceBucket}/{SourceKey} to {DestinationBucket}/{DestinationKey}",
sourceBucket, sourceKey, destinationBucket, destinationKey); sourceBucket, sourceKey, destinationBucket, destinationKey);
return Result.Error($"Failed to copy file from S3 with bucket: {sourceBucket} and key: {sourceKey} to bucket: {destinationBucket} and key: {destinationKey}"); return Result.Error($"Failed to copy from {sourceBucket}/{sourceKey} to {destinationBucket}/{destinationKey}");
} }
} }
} }