Skip to content

Commit

Permalink
Remove unnecessary transaction handling from dispatch worker
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken committed Apr 2, 2024
1 parent 4b8401d commit ff3b6a8
Showing 1 changed file with 1 addition and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,20 @@
namespace MinimalDomainEvents.Outbox.Worker;
internal sealed class BackgroundDispatchWorker : BackgroundService
{
private const int Delay = 2 * 1000;
private const int Delay = 1000;

private readonly IOutboxRecordCollectionInitializer _outboxRecordCollectionInitializer;
private readonly ITransactionProvider _transactionFactory;
private readonly IDomainEventRetriever _domainEventRetriever;
private readonly ICleanupOutboxRecords _cleanupOutboxRecords;
private readonly IEnumerable<IDispatchDomainEvents> _dispatchers;

public BackgroundDispatchWorker(IOutboxRecordCollectionInitializer outboxRecordCollectionInitializer,
ITransactionProvider transactionFactory,
IDomainEventRetriever domainEventRetriever,
ICleanupOutboxRecords cleanupOutboxRecords,
IEnumerable<IDispatchDomainEvents> dispatchers)
{
_domainEventRetriever = domainEventRetriever;
_outboxRecordCollectionInitializer = outboxRecordCollectionInitializer;
_transactionFactory = transactionFactory;
_cleanupOutboxRecords = cleanupOutboxRecords;
_dispatchers = dispatchers;
}
Expand All @@ -34,7 +31,6 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)

while (!stoppingToken.IsCancellationRequested)
{
using var transaction = await _transactionFactory.NewTransaction(stoppingToken);
var domainEvents = await _domainEventRetriever.GetAndMarkAsDispatched(stoppingToken);

if (domainEvents is not null && domainEvents.Count > 0)
Expand All @@ -44,7 +40,6 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
}

await _cleanupOutboxRecords.CleanupExpiredOutboxRecords(stoppingToken);
await transaction.Commit(stoppingToken);

await Task.Delay(Delay, stoppingToken);
}
Expand Down

0 comments on commit ff3b6a8

Please sign in to comment.