Reworks
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using MassTransit;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Musify.Application.Contracts.Infrastructure;
|
||||
using Musify.Domain.Entities;
|
||||
@@ -6,42 +7,41 @@ using Musify.Infrastructure.MassTransit.Activities.Arguments;
|
||||
|
||||
namespace Musify.Infrastructure.MassTransit.Activities
|
||||
{
|
||||
public class GenerateAudioWorkflowPathsActivity(
|
||||
ILogger<GenerateAudioWorkflowPathsActivity> logger,
|
||||
IProcessTrackingStore processTrackingStore)
|
||||
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)
|
||||
{
|
||||
var processId = await processTrackingStore.GetOrCreateProcessAsync(
|
||||
"RoutingSlip",
|
||||
executeContext.CorrelationId ?? executeContext.TrackingNumber,
|
||||
executeContext.ConversationId,
|
||||
executeContext.MessageId,
|
||||
executeContext.CancellationToken);
|
||||
|
||||
var stepId = await processTrackingStore.StartStepAsync(
|
||||
processId,
|
||||
nameof(GenerateAudioWorkflowPathsActivity),
|
||||
ProcessStepComponentType.Activity,
|
||||
0,
|
||||
executeContext.CancellationToken);
|
||||
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);
|
||||
logger.LogDebug("Generated audio workflow paths in {WorkingDirectory}", workingDirectory);
|
||||
|
||||
await processTrackingStore.CompleteStepAsync(processId, stepId, executeContext.CancellationToken);
|
||||
return executeContext.CompletedWithVariables(new Dictionary<string, object>
|
||||
{
|
||||
[RoutingSlipVariableNames.Workflow.TemporalDirectory] = workingDirectory,
|
||||
@@ -54,9 +54,20 @@ namespace Musify.Infrastructure.MassTransit.Activities
|
||||
{
|
||||
logger.LogError(exception, "Failed to generate audio workflow paths for {SourceKey}",
|
||||
executeContext.Arguments.SourceKey);
|
||||
await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user