Class: PubSubModelSync::Transaction
- Defined in:
- lib/pub_sub_model_sync/transaction.rb
Constant Summary collapse
- PUBLISHER_KLASS =
PubSubModelSync::MessagePublisher
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#finished ⇒ Object
Returns the value of attribute finished.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#key ⇒ Object
Returns the value of attribute key.
-
#max_buffer ⇒ Object
Returns the value of attribute max_buffer.
-
#payloads ⇒ Object
Returns the value of attribute payloads.
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
-
#add_payload(payload) ⇒ Object
TODO: remove buffer (already managed by pubsub services when running with config.async = true).
- #add_transaction(transaction) ⇒ Object
- #clean_publisher ⇒ Object
- #deliver_all ⇒ Object
-
#finish ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#initialize(key, max_buffer: config.transactions_max_buffer, headers: {}) ⇒ Transaction
constructor
A new instance of Transaction.
- #rollback ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(key, max_buffer: config.transactions_max_buffer, headers: {}) ⇒ Transaction
Returns a new instance of Transaction.
12 13 14 15 16 17 18 |
# File 'lib/pub_sub_model_sync/transaction.rb', line 12 def initialize(key, max_buffer: config.transactions_max_buffer, headers: {}) @key = key @max_buffer = max_buffer @children = [] @payloads = [] @headers = headers end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
6 7 8 |
# File 'lib/pub_sub_model_sync/transaction.rb', line 6 def children @children end |
#finished ⇒ Object
Returns the value of attribute finished.
6 7 8 |
# File 'lib/pub_sub_model_sync/transaction.rb', line 6 def finished @finished end |
#headers ⇒ Object
Returns the value of attribute headers.
6 7 8 |
# File 'lib/pub_sub_model_sync/transaction.rb', line 6 def headers @headers end |
#key ⇒ Object
Returns the value of attribute key.
6 7 8 |
# File 'lib/pub_sub_model_sync/transaction.rb', line 6 def key @key end |
#max_buffer ⇒ Object
Returns the value of attribute max_buffer.
6 7 8 |
# File 'lib/pub_sub_model_sync/transaction.rb', line 6 def max_buffer @max_buffer end |
#payloads ⇒ Object
Returns the value of attribute payloads.
6 7 8 |
# File 'lib/pub_sub_model_sync/transaction.rb', line 6 def payloads @payloads end |
#root ⇒ Object
Returns the value of attribute root.
6 7 8 |
# File 'lib/pub_sub_model_sync/transaction.rb', line 6 def root @root end |
Instance Method Details
#add_payload(payload) ⇒ Object
TODO: remove buffer (already managed by pubsub services when running with config.async = true)
22 23 24 25 |
# File 'lib/pub_sub_model_sync/transaction.rb', line 22 def add_payload(payload) payloads << payload deliver_payloads end |
#add_transaction(transaction) ⇒ Object
36 37 38 39 40 |
# File 'lib/pub_sub_model_sync/transaction.rb', line 36 def add_transaction(transaction) transaction.root = self children << transaction transaction end |
#clean_publisher ⇒ Object
48 49 50 |
# File 'lib/pub_sub_model_sync/transaction.rb', line 48 def clean_publisher PUBLISHER_KLASS.current_transaction = nil if !root && children.empty? end |
#deliver_all ⇒ Object
52 53 54 55 |
# File 'lib/pub_sub_model_sync/transaction.rb', line 52 def deliver_all deliver_payloads clean_publisher end |
#finish ⇒ Object
rubocop:disable Metrics/AbcSize
27 28 29 30 31 32 33 34 |
# File 'lib/pub_sub_model_sync/transaction.rb', line 27 def finish # rubocop:disable Metrics/AbcSize if root root.children = root.children.reject { |t| t == self } root.deliver_all if root.finished && root.children.empty? end self.finished = true deliver_all if children.empty? end |
#rollback ⇒ Object
42 43 44 45 46 |
# File 'lib/pub_sub_model_sync/transaction.rb', line 42 def rollback self.children = [] root&.rollback clean_publisher end |