Class: OllamaAgent::Runtime::CompensationManifest
- Inherits:
-
Object
- Object
- OllamaAgent::Runtime::CompensationManifest
- Defined in:
- lib/ollama_agent/runtime/compensation_manifest.rb
Overview
SQLite-backed ledger of per-path compensation steps for a saga manifest_id.
Constant Summary collapse
- INSERT_COMPENSATION_SQL =
"INSERT INTO compensations " \ "(manifest_id, path, op, pre_blob_sha, pre_existed, fencing_token, " \ "logical_stamp, applied) VALUES (?,?,?,?,?,?,?,0)"
Instance Method Summary collapse
-
#each_unapplied(manifest_id:, &block) ⇒ Object
rubocop:enable Metrics/ParameterLists, Naming/MethodParameterName.
-
#initialize(db) ⇒ CompensationManifest
constructor
A new instance of CompensationManifest.
- #mark_applied(id:) ⇒ Object
-
#record(manifest_id:, path:, op:, pre_blob_sha:, pre_existed:, fencing_token:, logical_stamp:) ⇒ Object
rubocop:disable Metrics/ParameterLists, Naming/MethodParameterName –
opmatches DB column.
Constructor Details
#initialize(db) ⇒ CompensationManifest
Returns a new instance of CompensationManifest.
11 12 13 |
# File 'lib/ollama_agent/runtime/compensation_manifest.rb', line 11 def initialize(db) @db = db end |
Instance Method Details
#each_unapplied(manifest_id:, &block) ⇒ Object
rubocop:enable Metrics/ParameterLists, Naming/MethodParameterName
29 30 31 32 33 34 |
# File 'lib/ollama_agent/runtime/compensation_manifest.rb', line 29 def each_unapplied(manifest_id:, &block) return enum_for(:each_unapplied, manifest_id: manifest_id) unless block sql = "SELECT * FROM compensations WHERE manifest_id = ? AND applied = 0 ORDER BY id DESC" @db.execute(sql, [manifest_id], &block) end |
#mark_applied(id:) ⇒ Object
36 37 38 39 40 |
# File 'lib/ollama_agent/runtime/compensation_manifest.rb', line 36 def mark_applied(id:) @db.transaction(:immediate) do @db.execute("UPDATE compensations SET applied = 1 WHERE id = ?", [id.to_i]) end end |
#record(manifest_id:, path:, op:, pre_blob_sha:, pre_existed:, fencing_token:, logical_stamp:) ⇒ Object
rubocop:disable Metrics/ParameterLists, Naming/MethodParameterName – op matches DB column
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ollama_agent/runtime/compensation_manifest.rb', line 16 def record(manifest_id:, path:, op:, pre_blob_sha:, pre_existed:, fencing_token:, logical_stamp:) insert_compensation_row( manifest_id: manifest_id, path: path, operation: op, pre_blob_sha: pre_blob_sha, pre_existed: pre_existed, fencing_token: fencing_token, logical_stamp: logical_stamp ) end |