110 lines
4.5 KiB
C#
110 lines
4.5 KiB
C#
using System;
|
|
using Svrnty.CQRS.Events.Abstractions.Replay;
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Svrnty.CQRS.Events.Abstractions.Models;
|
|
|
|
namespace Svrnty.CQRS.Events.Abstractions.Replay;
|
|
|
|
/// <summary>
|
|
/// Service for replaying historical events from persistent streams.
|
|
/// Enables rebuilding projections, reprocessing events, and time-travel debugging.
|
|
/// </summary>
|
|
public interface IEventReplayService
|
|
{
|
|
/// <summary>
|
|
/// Replay events from a specific offset.
|
|
/// </summary>
|
|
/// <param name="streamName">Stream to replay from.</param>
|
|
/// <param name="startOffset">Starting offset (inclusive).</param>
|
|
/// <param name="options">Replay options.</param>
|
|
/// <param name="cancellationToken">Cancellation token.</param>
|
|
/// <returns>Async enumerable of events.</returns>
|
|
/// <remarks>
|
|
/// Events are returned in offset order (oldest first).
|
|
/// Use ReplayOptions to control batch size, rate limiting, and filtering.
|
|
/// </remarks>
|
|
IAsyncEnumerable<StoredEvent> ReplayFromOffsetAsync(
|
|
string streamName,
|
|
long startOffset,
|
|
ReplayOptions? options = null,
|
|
CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Replay events from a specific timestamp.
|
|
/// </summary>
|
|
/// <param name="streamName">Stream to replay from.</param>
|
|
/// <param name="startTime">Starting timestamp (UTC, inclusive).</param>
|
|
/// <param name="options">Replay options.</param>
|
|
/// <param name="cancellationToken">Cancellation token.</param>
|
|
/// <returns>Async enumerable of events.</returns>
|
|
/// <remarks>
|
|
/// Finds the first event at or after the specified timestamp.
|
|
/// All subsequent events are returned in order.
|
|
/// </remarks>
|
|
IAsyncEnumerable<StoredEvent> ReplayFromTimeAsync(
|
|
string streamName,
|
|
DateTimeOffset startTime,
|
|
ReplayOptions? options = null,
|
|
CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Replay events within a time range.
|
|
/// </summary>
|
|
/// <param name="streamName">Stream to replay from.</param>
|
|
/// <param name="startTime">Starting timestamp (UTC, inclusive).</param>
|
|
/// <param name="endTime">Ending timestamp (UTC, exclusive).</param>
|
|
/// <param name="options">Replay options.</param>
|
|
/// <param name="cancellationToken">Cancellation token.</param>
|
|
/// <returns>Async enumerable of events.</returns>
|
|
/// <remarks>
|
|
/// Only events with stored_at >= startTime AND stored_at < endTime are returned.
|
|
/// Useful for replaying specific time periods.
|
|
/// </remarks>
|
|
IAsyncEnumerable<StoredEvent> ReplayTimeRangeAsync(
|
|
string streamName,
|
|
DateTimeOffset startTime,
|
|
DateTimeOffset endTime,
|
|
ReplayOptions? options = null,
|
|
CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Replay all events in a stream from the beginning.
|
|
/// </summary>
|
|
/// <param name="streamName">Stream to replay from.</param>
|
|
/// <param name="options">Replay options.</param>
|
|
/// <param name="cancellationToken">Cancellation token.</param>
|
|
/// <returns>Async enumerable of events.</returns>
|
|
/// <remarks>
|
|
/// Equivalent to ReplayFromOffsetAsync(streamName, 0, options).
|
|
/// Use for complete stream replay when rebuilding projections.
|
|
/// </remarks>
|
|
IAsyncEnumerable<StoredEvent> ReplayAllAsync(
|
|
string streamName,
|
|
ReplayOptions? options = null,
|
|
CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Get the total count of events that would be replayed.
|
|
/// </summary>
|
|
/// <param name="streamName">Stream to count events for.</param>
|
|
/// <param name="startOffset">Starting offset (optional).</param>
|
|
/// <param name="startTime">Starting timestamp (optional).</param>
|
|
/// <param name="endTime">Ending timestamp (optional).</param>
|
|
/// <param name="options">Replay options (for event type filtering).</param>
|
|
/// <param name="cancellationToken">Cancellation token.</param>
|
|
/// <returns>Count of events matching the criteria.</returns>
|
|
/// <remarks>
|
|
/// Useful for estimating replay duration and showing progress.
|
|
/// Counts only events matching the event type filter if specified.
|
|
/// </remarks>
|
|
Task<long> GetReplayCountAsync(
|
|
string streamName,
|
|
long? startOffset = null,
|
|
DateTimeOffset? startTime = null,
|
|
DateTimeOffset? endTime = null,
|
|
ReplayOptions? options = null,
|
|
CancellationToken cancellationToken = default);
|
|
}
|