Class: Mammoth::PersistedPayloadDeserializer
- Inherits:
-
Object
- Object
- Mammoth::PersistedPayloadDeserializer
- Defined in:
- lib/mammoth/persisted_payload_deserializer.rb
Overview
Reconstructs exact CDC core work items from persisted webhook payloads.
Dead letters and sample files contain Mammoth's JSON delivery projection, not live CDC objects. This class is the explicit boundary that converts those persisted representations back into core vocabulary.
Class Method Summary collapse
-
.event(payload) ⇒ CDC::Core::ChangeEvent
Deserialize one persisted event payload.
-
.transaction(payload) ⇒ CDC::Core::TransactionEnvelope
Deserialize one persisted transaction payload.
Class Method Details
.event(payload) ⇒ CDC::Core::ChangeEvent
Deserialize one persisted event payload.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mammoth/persisted_payload_deserializer.rb', line 17 def event(payload) attributes = stringify_keys(payload) data = attributes["data"] = (attributes) CDC::Core::ChangeEvent.new( operation: attributes.fetch("operation"), schema: attributes["namespace"] || attributes.fetch("schema"), table: attributes["entity"] || attributes.fetch("table"), old_values: attributes["old_values"] || delete_values(attributes, data), new_values: attributes["new_values"] || changed_values(attributes, data), primary_key: attributes["identity"] || attributes["primary_key"], transaction_id: attributes["transaction_id"], commit_lsn: attributes["commit_lsn"] || attributes["source_position"], sequence_number: attributes["sequence_number"], occurred_at: parse_time(attributes["occurred_at"]), metadata: ) rescue KeyError, ArgumentError, TypeError => e raise ConfigurationError, "invalid persisted CDC event: #{e.}" end |
.transaction(payload) ⇒ CDC::Core::TransactionEnvelope
Deserialize one persisted transaction payload.
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mammoth/persisted_payload_deserializer.rb', line 43 def transaction(payload) attributes = stringify_keys(payload) CDC::Core::TransactionEnvelope.new( transaction_id: attributes.fetch("transaction_id"), events: attributes.fetch("events").map { |event_payload| event(event_payload) }, commit_lsn: attributes["commit_lsn"] || attributes["source_position"], committed_at: parse_time(attributes["committed_at"]), metadata: (attributes) ) rescue KeyError, ArgumentError, TypeError => e raise ConfigurationError, "invalid persisted CDC transaction: #{e.}" end |