chore: import MusifyBackend into monorepo (preserving history)
git-subtree-dir: MusifyBackend git-subtree-mainline:6829e769edgit-subtree-split:ed7b00c2cc
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
using MassTransit;
|
||||
using Musify.Application.Events;
|
||||
using Musify.Infrastructure.MassTransit.RoutingSlip.Builders;
|
||||
|
||||
namespace Musify.Infrastructure.MassTransit.Consumers
|
||||
{
|
||||
public class CreatePlayListConsumer(
|
||||
IBus bus,
|
||||
PlayListPictureSourceRoutingSlipBuilder routingSlipBuilder)
|
||||
: IConsumer<CreatePlayListResourcesEvent>
|
||||
{
|
||||
public const string QueueName = "create-playList";
|
||||
|
||||
public async Task Consume(ConsumeContext<CreatePlayListResourcesEvent> consumeContext)
|
||||
{
|
||||
var routingSlip = routingSlipBuilder
|
||||
.Build(consumeContext.Message, consumeContext.CorrelationId)
|
||||
.Build();
|
||||
|
||||
await bus.Execute(routingSlip);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using MassTransit;
|
||||
using Musify.Application.Events;
|
||||
using Musify.Infrastructure.MassTransit.RoutingSlip.Builders;
|
||||
|
||||
namespace Musify.Infrastructure.MassTransit.Consumers
|
||||
{
|
||||
public class CreateTrackConsumer(
|
||||
IBus bus,
|
||||
CreateTrackRoutingSlipBuilder routingSlipBuilder)
|
||||
: IConsumer<CreateTrackResourcesEvent>
|
||||
{
|
||||
public const string QueueName = "create-track";
|
||||
|
||||
public async Task Consume(ConsumeContext<CreateTrackResourcesEvent> consumeContext)
|
||||
{
|
||||
var routingSlip = routingSlipBuilder
|
||||
.Build(consumeContext.Message, consumeContext.CorrelationId)
|
||||
.Build();
|
||||
|
||||
await bus.Execute(routingSlip);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using MassTransit;
|
||||
using Musify.Application.Events;
|
||||
using Musify.Infrastructure.MassTransit.RoutingSlip.Builders;
|
||||
|
||||
namespace Musify.Infrastructure.MassTransit.Consumers
|
||||
{
|
||||
public class DeletePlayListConsumer(
|
||||
IBus bus,
|
||||
DeletePlayListRoutingSlipBuilder routingSlipBuilder)
|
||||
: IConsumer<DeletePlayListEvent>
|
||||
{
|
||||
public const string QueueName = "delete-playList";
|
||||
|
||||
public async Task Consume(ConsumeContext<DeletePlayListEvent> consumeContext)
|
||||
{
|
||||
var routingSlip = (await routingSlipBuilder
|
||||
.BuildAsync(
|
||||
consumeContext.Message.PlayListId,
|
||||
consumeContext.Message.UserId,
|
||||
consumeContext.CorrelationId,
|
||||
consumeContext.CancellationToken))
|
||||
.Build();
|
||||
|
||||
await bus.Execute(routingSlip);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using MassTransit;
|
||||
using Musify.Application.Events;
|
||||
using Musify.Infrastructure.MassTransit.RoutingSlip.Builders;
|
||||
|
||||
namespace Musify.Infrastructure.MassTransit.Consumers
|
||||
{
|
||||
public class DeleteTrackConsumer(
|
||||
IBus bus,
|
||||
DeleteTrackRoutingSlipBuilder routingSlipBuilder)
|
||||
: IConsumer<DeleteTrackEvent>
|
||||
{
|
||||
public const string QueueName = "delete-track";
|
||||
|
||||
public async Task Consume(ConsumeContext<DeleteTrackEvent> consumeContext)
|
||||
{
|
||||
var routingSlip = (await routingSlipBuilder
|
||||
.BuildAsync(consumeContext.Message.TrackId, consumeContext.Message.UserId, consumeContext.CorrelationId, consumeContext.CancellationToken))
|
||||
.Build();
|
||||
|
||||
await bus.Execute(routingSlip);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Musify.Infrastructure.MassTransit.Consumers
|
||||
{
|
||||
internal static class EndpointHelper
|
||||
{
|
||||
internal static Uri BuildExecuteActivityUri(string endpointName) => new($"queue:{endpointName}_execute");
|
||||
|
||||
internal static Uri BuildCompensateActivityUri(string endpointName) => new($"queue:{endpointName}_compensate");
|
||||
|
||||
internal static Uri BuildConsumerUri(string endpointName) => new($"queue:{endpointName}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using MassTransit;
|
||||
using MassTransit.Courier.Contracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Musify.Infrastructure.MassTransit.Consumers
|
||||
{
|
||||
public class RoutingSlipCleanUpConsumer(
|
||||
ILogger<RoutingSlipCleanUpConsumer> logger) :
|
||||
IConsumer<RoutingSlipCompleted>,
|
||||
IConsumer<RoutingSlipFaulted>
|
||||
{
|
||||
public const string QueueName = "routing-slip-events";
|
||||
|
||||
public Task Consume(ConsumeContext<RoutingSlipCompleted> consumeContext)
|
||||
=> DeleteFolder(consumeContext.Message.Variables);
|
||||
|
||||
public Task Consume(ConsumeContext<RoutingSlipFaulted> consumeContext)
|
||||
=> DeleteFolder(consumeContext.Message.Variables);
|
||||
|
||||
Task DeleteFolder(IDictionary<string, object> variables)
|
||||
{
|
||||
if (!variables.TryGetValue(RoutingSlipVariableNames.Workflow.TemporalDirectory, out var pathObject))
|
||||
return Task.CompletedTask;
|
||||
|
||||
var pathString = pathObject.ToString();
|
||||
|
||||
if (string.IsNullOrEmpty(pathString))
|
||||
return Task.CompletedTask;
|
||||
|
||||
try
|
||||
{
|
||||
Directory.Delete(pathString, recursive: true);
|
||||
logger.LogInformation("Deleted temporal directory at path {Path}", pathString);
|
||||
}
|
||||
catch (DirectoryNotFoundException directoryNotFoundException)
|
||||
{
|
||||
logger.LogWarning(directoryNotFoundException, "Temporal directory at path {Path} was not found for deletion", pathString);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to delete temporal directory at path {Path}", pathString);
|
||||
throw;
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using MassTransit;
|
||||
using Musify.Application.Events;
|
||||
using Musify.Infrastructure.MassTransit.RoutingSlip.Builders;
|
||||
|
||||
namespace Musify.Infrastructure.MassTransit.Consumers
|
||||
{
|
||||
public class UpdatePlayListPictureConsumer(
|
||||
IBus bus,
|
||||
PictureWorkflowRoutingSlipBuilder routingSlipBuilder)
|
||||
: IConsumer<UpdatePlayListPictureEvent>
|
||||
{
|
||||
public const string QueueName = "update-playList-picture";
|
||||
|
||||
public async Task Consume(ConsumeContext<UpdatePlayListPictureEvent> consumeContext)
|
||||
{
|
||||
var routingSlip = routingSlipBuilder
|
||||
.Build(consumeContext.Message, consumeContext.CorrelationId)
|
||||
.Build();
|
||||
|
||||
await bus.Execute(routingSlip);
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
using MassTransit;
|
||||
using Musify.Application.Events;
|
||||
using Musify.Infrastructure.MassTransit.RoutingSlip.Builders;
|
||||
|
||||
namespace Musify.Infrastructure.MassTransit.Consumers
|
||||
{
|
||||
public class UpdatePlayListPictureSourceConsumer(
|
||||
IBus bus,
|
||||
PlayListPictureSourceRoutingSlipBuilder routingSlipBuilder)
|
||||
: IConsumer<UpdatePlayListPictureSourceEvent>
|
||||
{
|
||||
public const string QueueName = "update-playList-picture-source";
|
||||
|
||||
public async Task Consume(ConsumeContext<UpdatePlayListPictureSourceEvent> consumeContext)
|
||||
{
|
||||
var routingSlip = routingSlipBuilder
|
||||
.Build(consumeContext.Message, consumeContext.CorrelationId)
|
||||
.Build();
|
||||
|
||||
await bus.Execute(routingSlip);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using MassTransit;
|
||||
using Musify.Application.Events;
|
||||
using Musify.Infrastructure.MassTransit.RoutingSlip.Builders;
|
||||
|
||||
namespace Musify.Infrastructure.MassTransit.Consumers
|
||||
{
|
||||
public class UpdateTrackAudioConsumer(
|
||||
IBus bus,
|
||||
AudioWorkflowRoutingSlipBuilder routingSlipBuilder)
|
||||
: IConsumer<UpdateTrackAudioEvent>
|
||||
{
|
||||
public const string QueueName = "update-track-audio";
|
||||
|
||||
public async Task Consume(ConsumeContext<UpdateTrackAudioEvent> consumeContext)
|
||||
{
|
||||
var routingSlip = routingSlipBuilder
|
||||
.Build(consumeContext.Message, consumeContext.CorrelationId)
|
||||
.Build();
|
||||
|
||||
await bus.Execute(routingSlip);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using MassTransit;
|
||||
using Musify.Application.Events;
|
||||
using Musify.Infrastructure.MassTransit.RoutingSlip.Builders;
|
||||
|
||||
namespace Musify.Infrastructure.MassTransit.Consumers
|
||||
{
|
||||
public class UpdateTrackPictureConsumer(
|
||||
IBus bus,
|
||||
PictureWorkflowRoutingSlipBuilder routingSlipBuilder)
|
||||
: IConsumer<UpdateTrackPictureEvent>
|
||||
{
|
||||
public const string QueueName = "update-track-picture";
|
||||
|
||||
public async Task Consume(ConsumeContext<UpdateTrackPictureEvent> consumeContext)
|
||||
{
|
||||
var routingSlip = routingSlipBuilder
|
||||
.Build(consumeContext.Message, consumeContext.CorrelationId)
|
||||
.Build();
|
||||
|
||||
await bus.Execute(routingSlip);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user