Class: Sequent::Core::AggregateSnapshotter
- Inherits:
-
BaseCommandHandler
- Object
- BaseCommandHandler
- Sequent::Core::AggregateSnapshotter
- Defined in:
- lib/sequent/core/aggregate_snapshotter.rb
Instance Attribute Summary
Attributes inherited from BaseCommandHandler
Instance Method Summary collapse
- #handles_message?(message) ⇒ Boolean
-
#SnapshotCommand ⇒ Object
Take up to ‘limit` snapshots when needed.
- #take_snapshot!(aggregate_id) ⇒ Object
Methods inherited from BaseCommandHandler
Methods included from Helpers::SelfApplier
Methods included from Helpers::UuidHelper
Constructor Details
This class inherits a constructor from Sequent::Core::BaseCommandHandler
Instance Method Details
#handles_message?(message) ⇒ Boolean
9 10 11 |
# File 'lib/sequent/core/aggregate_snapshotter.rb', line 9 def () .is_a? SnapshotCommand end |
#SnapshotCommand ⇒ Object
Take up to ‘limit` snapshots when needed. Throws `:done` when done.
16 17 18 19 20 21 22 23 |
# File 'lib/sequent/core/aggregate_snapshotter.rb', line 16 on SnapshotCommand do |command| aggregate_ids = repository.event_store.aggregates_that_need_snapshots(@last_aggregate_id, command.limit) aggregate_ids.each do |aggregate_id| take_snapshot!(aggregate_id) end @last_aggregate_id = aggregate_ids.last throw :done if @last_aggregate_id.nil? end |
#take_snapshot!(aggregate_id) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/sequent/core/aggregate_snapshotter.rb', line 25 def take_snapshot!(aggregate_id) aggregate = @repository.load_aggregate(aggregate_id) Sequent.logger.info "Taking snapshot for aggregate #{aggregate}" aggregate.take_snapshot! rescue => e Sequent.logger.warn "Failed to take snapshot for aggregate #{aggregate_id}: #{e}", e.inspect end |