Class: OllamaAgent::Runtime::EventStore
- Inherits:
-
Object
- Object
- OllamaAgent::Runtime::EventStore
- Defined in:
- lib/ollama_agent/runtime/event_store.rb
Overview
Append-only event log in event_store.db.
Constant Summary collapse
- MUTATION_KIND =
"mutation"
Instance Method Summary collapse
-
#append(manifest_id:, logical_stamp:, kind:, payload:, intent_hash: nil, created_at: nil) ⇒ :inserted, :duplicate
Appends one event.
-
#each_for(manifest_id:, &block) ⇒ Object
Yields each event row for
manifest_idinidorder (results_as_hashkeys are strings). -
#each_mutation_globally(&block) ⇒ Object
All mutation events in global
idorder (workspace-level WAL replay). -
#initialize(db) ⇒ EventStore
constructor
A new instance of EventStore.
Constructor Details
#initialize(db) ⇒ EventStore
Returns a new instance of EventStore.
12 13 14 |
# File 'lib/ollama_agent/runtime/event_store.rb', line 12 def initialize(db) @db = db end |
Instance Method Details
#append(manifest_id:, logical_stamp:, kind:, payload:, intent_hash: nil, created_at: nil) ⇒ :inserted, :duplicate
Appends one event. created_at must be a logical stamp (no wall clock); defaults to logical_stamp. rubocop:disable Metrics/ParameterLists – explicit event fields
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ollama_agent/runtime/event_store.rb', line 19 def append(manifest_id:, logical_stamp:, kind:, payload:, intent_hash: nil, created_at: nil) stamp = created_at || logical_stamp blob = payload_to_blob(payload) insert_event_row([manifest_id, logical_stamp, kind, blob, intent_hash, stamp]) :inserted rescue SQLite3::ConstraintException => e raise unless intent_hash && intent_hash_duplicate_constraint?(e) :duplicate end |
#each_for(manifest_id:, &block) ⇒ Object
Yields each event row for manifest_id in id order (results_as_hash keys are strings).
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ollama_agent/runtime/event_store.rb', line 32 def each_for(manifest_id:, &block) return to_enum(:each_for, manifest_id: manifest_id) unless block @db.execute( "SELECT id, manifest_id, logical_stamp, kind, payload, intent_hash, created_at " \ "FROM events WHERE manifest_id = ? ORDER BY id ASC", [manifest_id], &block ) end |
#each_mutation_globally(&block) ⇒ Object
All mutation events in global id order (workspace-level WAL replay).
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ollama_agent/runtime/event_store.rb', line 44 def each_mutation_globally(&block) return to_enum(:each_mutation_globally) unless block @db.execute( "SELECT id, manifest_id, logical_stamp, kind, payload, intent_hash, created_at " \ "FROM events WHERE kind = ? ORDER BY id ASC", [MUTATION_KIND], &block ) end |