Changes but failing

This commit is contained in:
2026-03-23 03:13:08 +01:00
parent 27ec670e3a
commit 4ec4b50c40
16 changed files with 362 additions and 160 deletions
@@ -1,4 +1,5 @@
using MassTransit;
using Microsoft.Extensions.Logging;
using Musify.Application.Contracts.Infrastructure;
using Musify.Domain.Entities;
using Musify.Infrastructure.Messaging.Activities.Arguments;
@@ -6,14 +7,14 @@ using Musify.Infrastructure.Messaging.Activities.Arguments;
namespace Musify.Infrastructure.Messaging.Activities
{
public class ResizePictureActivity(
IStorageHandler storageHandler,
IPictureHandler pictureHandler,
ILogger<ResizePictureActivity> logger,
IProcessTrackingStore processTrackingStore)
: IExecuteActivity<ResizePictureArgument>
: IExecuteActivity<ResizePictureLocalArguments>
{
public const string ExecuteEndpointName = "Resize-Picture";
public async Task<ExecutionResult> Execute(ExecuteContext<ResizePictureArgument> executeContext)
public async Task<ExecutionResult> Execute(ExecuteContext<ResizePictureLocalArguments> executeContext)
{
var processId = await processTrackingStore.GetOrCreateProcessAsync(
"RoutingSlip",
@@ -31,47 +32,54 @@ namespace Musify.Infrastructure.Messaging.Activities
try
{
var file = await storageHandler.GetFileAsync(
executeContext.Arguments.OriginalBucketName,
executeContext.Arguments.OriginalKeyName,
executeContext.CancellationToken);
if (!file.IsSuccess)
if (!File.Exists(executeContext.Arguments.SourceFilePath))
{
string errorMessages = string.Join(", ", file.Errors);
throw new Exception(errorMessages);
logger.LogError("Source file not found at {SourceFilePath}",
executeContext.Arguments.SourceFilePath);
throw new FileNotFoundException($"Source file not found: {executeContext.Arguments.SourceFilePath}");
}
await using var fileStream = File.OpenRead(executeContext.Arguments.SourceFilePath);
var resizedPicture = await pictureHandler.ResizePictureAsync(
file.Value,
fileStream,
executeContext.Arguments.Width,
executeContext.Arguments.Height,
executeContext.CancellationToken);
if (!resizedPicture.IsSuccess)
{
string errorMessage = string.Join(", ", resizedPicture.Errors);
var errorMessage = string.Join("; ", resizedPicture.Errors);
logger.LogError("Failed to resize picture {SourceFilePath} to {Width}x{Height}. Errors: {Errors}",
executeContext.Arguments.SourceFilePath,
executeContext.Arguments.Width,
executeContext.Arguments.Height,
errorMessage);
throw new Exception(errorMessage);
}
var uploadFile = await storageHandler.UploadFileAsync(
resizedPicture.Value,
pictureHandler.ContentType,
executeContext.Arguments.DestinationBucketName,
executeContext.Arguments.DestinationKeyName,
executeContext.CancellationToken);
if (!uploadFile.IsSuccess)
var destinationDirectory = Path.GetDirectoryName(executeContext.Arguments.DestinationFilePath);
if (!string.IsNullOrEmpty(destinationDirectory))
{
var errorMessage = string.Join(", ", uploadFile.Errors);
throw new Exception(errorMessage);
Directory.CreateDirectory(destinationDirectory);
}
await using var destinationStream = File.Create(executeContext.Arguments.DestinationFilePath);
await resizedPicture.Value.CopyToAsync(destinationStream, executeContext.CancellationToken);
logger.LogInformation("Picture resized successfully from {SourceFilePath} to {DestinationFilePath} ( {Width}x{Height} )",
executeContext.Arguments.SourceFilePath,
executeContext.Arguments.DestinationFilePath,
executeContext.Arguments.Width,
executeContext.Arguments.Height);
await processTrackingStore.CompleteStepAsync(processId, stepId, executeContext.CancellationToken);
return executeContext.Completed();
}
catch (Exception exception)
{
logger.LogError(exception, "Error resizing picture {SourceFilePath}",
executeContext.Arguments.SourceFilePath);
await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken);
throw;
}