event-sourcing
Safe HaskellSafe-Inferred
LanguageGHC2021

Data.EventSource.Rotation

Description

Log rotation for an EventStore: fold the existing events into an aggregate, and once a configured number of events has accumulated, archive them under a log id and start a fresh log from a checkpoint event that captures the aggregate so far.

Synopsis

Documentation

newtype RotationConfig Source #

Rotate after this many events have been appended. Must be positive; a value of 0 would trigger a rotation immediately after every checkpoint.

Constructors

RotateAfter Natural 

data EventStore e m Source #

An EventSource and EventSink combined

Constructors

EventStore 

Fields

newRotatedEventStore Source #

Arguments

:: (HasEventId e, MonadUnliftIO m, MonadTime m, MonadLabelledSTM m) 
=> RotationConfig 
-> s

Starting state of aggregate

-> (s -> e -> s)

Update aggregate state

-> (s -> EventId -> UTCTime -> e)

Create a checkpoint event

-> EventStore e m 
-> m (EventStore e m) 

Creates an event store that rotates according to given config and StateAggregate.