Rework jobs

This commit is contained in:
2026-03-20 21:40:05 +01:00
parent 93a975e9b5
commit b34a711d2d
22 changed files with 449 additions and 157 deletions
@@ -1,31 +1,53 @@
using MassTransit;
using Microsoft.EntityFrameworkCore;
using Musify.Application.Contracts.Infrastructure;
using Musify.Domain.Entities;
using Musify.Infrastructure.Messaging.Activities.Arguments;
namespace Musify.Infrastructure.Messaging.Activities
{
public class UpdatePlayListPictureActivity(IDatabase database)
public class UpdatePlayListPictureActivity(IDatabase database, IProcessTrackingStore processTrackingStore)
: IExecuteActivity<UpdatePlayListPictureArguments>
{
public const string ExecuteEndpointName = "Update-PlayList-Picture";
public async Task<ExecutionResult> Execute(ExecuteContext<UpdatePlayListPictureArguments> executeContext)
{
var playList = await database.PlayLists.SingleOrDefaultAsync(p => p.Id == executeContext.Arguments.PlayListId,
var processId = await processTrackingStore.GetOrCreateProcessAsync(
"RoutingSlip",
executeContext.CorrelationId ?? executeContext.TrackingNumber,
executeContext.ConversationId,
executeContext.MessageId,
executeContext.CancellationToken);
if (playList is null)
throw new Exception($"PlayList with id {executeContext.Arguments.PlayListId} not found.");
var stepId = await processTrackingStore.StartStepAsync(
processId,
nameof(UpdatePlayListPictureActivity),
ProcessStepComponentType.Activity,
0,
executeContext.CancellationToken);
playList.SmallPictureKeyName = executeContext.Arguments.SmallPictureKeyName;
playList.MediumPictureKeyName = executeContext.Arguments.MediumPictureKeyName;
playList.LargePictureKeyName = executeContext.Arguments.LargePictureKeyName;
try
{
var playList = await database.PlayLists.FindAsync(executeContext.Arguments.PlayListId, executeContext.CancellationToken);
database.PlayLists.Update(playList);
await database.SaveChangesAsync(executeContext.CancellationToken);
if (playList is null)
throw new Exception($"PlayList with id {executeContext.Arguments.PlayListId} not found.");
return executeContext.Completed();
playList.SmallPictureKeyName = executeContext.Arguments.SmallPictureKeyName;
playList.MediumPictureKeyName = executeContext.Arguments.MediumPictureKeyName;
playList.LargePictureKeyName = executeContext.Arguments.LargePictureKeyName;
database.PlayLists.Update(playList);
await database.SaveChangesAsync(executeContext.CancellationToken);
await processTrackingStore.CompleteStepAsync(processId, stepId, executeContext.CancellationToken);
return executeContext.Completed();
}
catch (Exception exception)
{
await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken);
throw;
}
}
}
}