Skip to content

Commit

Permalink
Merge pull request #2 from sdc-ad/features/end_of_transaction_event
Browse files Browse the repository at this point in the history
Emit event when reaching end of event stream transaction
  • Loading branch information
prochnowc authored Oct 8, 2024
2 parents 7810aaf + 08b68ce commit 161d7ee
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace AppCoreNet.EventStore
{
/// <summary>
/// An event which is emitted before the transaction processing the event queue is committed.
/// This allows listeners to ensure any buffered work is completed before the transaction is committed.
/// </summary>
[EventType(nameof(EventTransactionCommittingEvent))]
public class EventTransactionCommittingEvent
{
}
}
24 changes: 24 additions & 0 deletions src/AppCoreNet.EventStore/Subscriptions/SubscriptionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,30 @@ await listener.HandleAsync(watchResult.SubscriptionId, @event, cancellationToken
}
}

try
{
await listener
.HandleAsync(
watchResult.SubscriptionId,
new EventEnvelope(new EventTransactionCommittingEvent()),
cancellationToken)
.ConfigureAwait(false);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error completing event transaction. This action will be retried.");

if (transaction != null)
{
await transaction.RollbackAsync()
.ConfigureAwait(false);
await transaction.DisposeAsync()
.ConfigureAwait(false);
}

continue;
}

await subscriptionStore.UpdateAsync(watchResult.SubscriptionId, lastPosition, cancellationToken)
.ConfigureAwait(false);

Expand Down

0 comments on commit 161d7ee

Please sign in to comment.