init
This commit is contained in:
commit
ab2e20f7e1
72 changed files with 2000 additions and 0 deletions
34
Femto.Modules.Media/Infrastructure/Integration/Outbox.cs
Normal file
34
Femto.Modules.Media/Infrastructure/Integration/Outbox.cs
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue