class Synapse::EventSourcing::SnapshotTaker
Represents a mechanism for creating snapshot events for aggregates
Implementations can choose whether to snapshot the aggregate in the calling thread or asynchronously, though it is typically done asynchronously.
@abstract
Attributes
event_store[RW]
@return [SnapshotEventStore]
executor[RW]
@return [Contender::Executor]
Public Class Methods
new()
click to toggle source
@return [undefined]
# File lib/synapse/event_sourcing/snapshot/taker.rb, line 17 def initialize @executor = Contender::DirectExecutor.new end
Public Instance Methods
schedule_snapshot(type_identifier, aggregate_id)
click to toggle source
Schedules a snapshot to be taken for an aggregate of the given type and with the given identifier
@param [String] type_identifier @param [Object] aggregate_id @return [undefined]
# File lib/synapse/event_sourcing/snapshot/taker.rb, line 27 def schedule_snapshot(type_identifier, aggregate_id) @executor.execute do stream = @event_store.read_events type_identifier, aggregate_id first_sequence_number = stream.peek.sequence_number snapshot = create_snapshot type_identifier, aggregate_id, stream if snapshot && snapshot.sequence_number > first_sequence_number @event_store.append_snapshot_event type_identifier, snapshot end end end
Protected Instance Methods
create_snapshot(type_identifier, aggregate_id, stream)
click to toggle source
@abstract @param [String] type_identifier @param [Object] aggregate_id @param [DomainEventStream] stream @return [DomainEventMessage]
# File lib/synapse/event_sourcing/snapshot/taker.rb, line 46 def create_snapshot(type_identifier, aggregate_id, stream) raise NotImplementedError end