This commit is contained in:
john 2025-05-03 15:38:57 +02:00
commit ab2e20f7e1
72 changed files with 2000 additions and 0 deletions

View file

@ -0,0 +1,34 @@
using System.Text.Json;
using Femto.Common.Integration;
using Femto.Modules.Media.Data;
using Microsoft.EntityFrameworkCore;
namespace Femto.Modules.Media.Infrastructure.Integration;
internal class Outbox(MediaContext context)
{
public async Task AddMessage<TMessage>(Guid aggregateId, TMessage message, CancellationToken cancellationToken)
where TMessage : IIntegrationEvent
{
await context.Outbox.AddAsync(
new(
message.EventId,
aggregateId,
typeof(TMessage).Name,
JsonSerializer.Serialize(message)
),
cancellationToken
);
}
public async Task<IEnumerable<OutboxEntry>> GetPendingMessages(CancellationToken cancellationToken)
{
var now = DateTime.UtcNow;
return await context
.Outbox.Where(message => message.Status == OutboxEntryStatus.Pending)
.Where(message => message.NextRetryAt == null || message.NextRetryAt <= now)
.OrderBy(message => message.CreatedAt)
.ToListAsync(cancellationToken);
}
}