Decree.Aggregates.AggregateStateBuilder (decree v0.1.0)

Copy Markdown View Source

Builds an aggregate's state by loading its snapshot and/or events from the event store.

Telemetry

  • [:decree, :aggregate, :populate, :start]

    • Description: Emitted when an aggregate begins loading from the event store
    • Measurements: %{system_time: integer()}
    • Metadata: %{application: Decree.Application.t(), aggregate_module: module(), aggregate_uuid: String.t(), aggregate_state: struct(), aggregate_version: non_neg_integer()}
  • [:decree, :aggregate, :populate, :stop]

    • Description: Emitted when an aggregate completes loading from the event store
    • Measurements: %{duration: non_neg_integer(), count: non_neg_integer()}
    • Metadata: %{application: Decree.Application.t(), aggregate_module: module(), aggregate_uuid: String.t(), aggregate_state: struct(), aggregate_version: non_neg_integer()}

Summary

Functions

Populate the aggregate's state from a snapshot, if present, and its events.

Load events from the event store, in batches, to rebuild the aggregate state

Functions

populate(state)

Populate the aggregate's state from a snapshot, if present, and its events.

Attempt to fetch a snapshot for the aggregate to use as its initial state. If the snapshot exists, fetch any subsequent events to rebuild its state. Otherwise start with the aggregate struct and stream all existing events for the aggregate from the event store to rebuild its state from those events.

Answers the %Aggregate{}, or {:error, :key_unknown} when a personal value in its snapshot or in an event its fold reads can't be read, or {:error, :unknown_event_type} when its stream holds an event of a type this release does not know (one appended by a newer release): the fold stops there, and never folds past it. It never raises for either.

rebuild_from_events(state)

Load events from the event store, in batches, to rebuild the aggregate state

Answers the %Aggregate{}, or {:error, :key_unknown} or {:error, :unknown_event_type} as populate/1 does.