A lot of changes
This commit is contained in:
@@ -40,12 +40,21 @@ namespace Musify.Application.Tracks.Handler
|
||||
return Result.Conflict("Track is currently being processed and cannot be deleted");
|
||||
}
|
||||
|
||||
var previousPicturesStatus = track.PicturesProcessingStatus;
|
||||
var previousAudioStatus = track.AudioTranscodeProcessingStatus;
|
||||
|
||||
track.PicturesProcessingStatus = ProcessingStatus.Processing;
|
||||
track.AudioTranscodeProcessingStatus = ProcessingStatus.Processing;
|
||||
|
||||
try
|
||||
{
|
||||
await eventBus.PublishAsync(
|
||||
new DeleteTrackEvent(track.Id, request.UserId),
|
||||
cancellationToken);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to publish delete track event for track {TrackId}", request.TrackId);
|
||||
return Result.Error($"Failed to delete track {request.TrackId}");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await database.SaveChangesAsync(cancellationToken);
|
||||
@@ -56,31 +65,6 @@ namespace Musify.Application.Tracks.Handler
|
||||
return Result.Error($"Failed to delete track {request.TrackId}");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await eventBus.PublishAsync(
|
||||
new DeleteTrackEvent(track.Id, request.UserId),
|
||||
cancellationToken);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to publish delete track event for track {TrackId}", request.TrackId);
|
||||
|
||||
track.PicturesProcessingStatus = previousPicturesStatus;
|
||||
track.AudioTranscodeProcessingStatus = previousAudioStatus;
|
||||
|
||||
try
|
||||
{
|
||||
await database.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception rollbackException)
|
||||
{
|
||||
logger.LogError(rollbackException, "Failed to rollback track {TrackId} processing flags after publish failure", request.TrackId);
|
||||
}
|
||||
|
||||
return Result.Error($"Failed to delete track {request.TrackId}");
|
||||
}
|
||||
|
||||
return Result.NoContent();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user