Class: CDC::Core::TransactionEnvelope
- Inherits:
-
Object
- Object
- CDC::Core::TransactionEnvelope
- Defined in:
- lib/cdc/core/transaction_envelope.rb
Overview
Immutable group of change events committed in one transaction.
TransactionEnvelope is useful when a downstream processor needs transaction boundaries instead of isolated row-level events. The contained events and metadata are Ractor-shareable when construction succeeds.
Instance Attribute Summary collapse
- #commit_lsn ⇒ Object, ... readonly
- #committed_at ⇒ Object, ... readonly
- #events ⇒ Object, ... readonly
- #metadata ⇒ Object, ... readonly
- #transaction_id ⇒ Object, ... readonly
Instance Method Summary collapse
-
#empty? ⇒ Boolean
Whether the envelope has no events.
-
#initialize(transaction_id:, events:, commit_lsn: nil, committed_at: nil, metadata: {}) ⇒ TransactionEnvelope
constructor
Build a transaction envelope.
-
#size ⇒ Integer
Number of events in the envelope.
-
#to_h ⇒ Hash{String=>Object,nil}
Convert the transaction envelope into a Ractor-shareable hash.
Constructor Details
#initialize(transaction_id:, events:, commit_lsn: nil, committed_at: nil, metadata: {}) ⇒ TransactionEnvelope
Build a transaction envelope.
25 26 27 28 29 30 31 32 |
# File 'lib/cdc/core/transaction_envelope.rb', line 25 def initialize(transaction_id:, events:, commit_lsn: nil, committed_at: nil, metadata: {}) @transaction_id = transaction_id @events = Ractor.make_shareable(events.freeze) @commit_lsn = commit_lsn&.to_s&.freeze @committed_at = committed_at @metadata = .is_a?(EventMetadata) ? : EventMetadata.new() Ractor.make_shareable(self) end |
Instance Attribute Details
#commit_lsn ⇒ Object, ... (readonly)
16 17 18 |
# File 'lib/cdc/core/transaction_envelope.rb', line 16 def commit_lsn @commit_lsn end |
#committed_at ⇒ Object, ... (readonly)
16 17 18 |
# File 'lib/cdc/core/transaction_envelope.rb', line 16 def committed_at @committed_at end |
#events ⇒ Object, ... (readonly)
16 17 18 |
# File 'lib/cdc/core/transaction_envelope.rb', line 16 def events @events end |
#metadata ⇒ Object, ... (readonly)
16 17 18 |
# File 'lib/cdc/core/transaction_envelope.rb', line 16 def @metadata end |
#transaction_id ⇒ Object, ... (readonly)
16 17 18 |
# File 'lib/cdc/core/transaction_envelope.rb', line 16 def transaction_id @transaction_id end |
Instance Method Details
#empty? ⇒ Boolean
Whether the envelope has no events.
37 |
# File 'lib/cdc/core/transaction_envelope.rb', line 37 def empty? = events.empty? |
#size ⇒ Integer
Number of events in the envelope.
42 |
# File 'lib/cdc/core/transaction_envelope.rb', line 42 def size = events.size |
#to_h ⇒ Hash{String=>Object,nil}
Convert the transaction envelope into a Ractor-shareable hash.
47 48 49 50 51 52 53 54 55 |
# File 'lib/cdc/core/transaction_envelope.rb', line 47 def to_h Ractor.make_shareable({ 'transaction_id' => transaction_id, 'events' => events.map(&:to_h).freeze, 'commit_lsn' => commit_lsn, 'committed_at' => committed_at, 'metadata' => .to_h }.freeze) end |