Module: ActiveRecord::ConnectionAdapters::CockroachDB::TransactionManagerMonkeyPatch
- Included in:
- TransactionManager
- Defined in:
- lib/active_record/connection_adapters/cockroachdb/transaction_manager.rb
Instance Method Summary collapse
-
#within_new_transaction(options = {}) ⇒ Object
Capture ActiveRecord::SerializationFailure errors caused by transactions that fail due to serialization errors.
Instance Method Details
#within_new_transaction(options = {}) ⇒ Object
Capture ActiveRecord::SerializationFailure errors caused by transactions that fail due to serialization errors. Failed transactions will be retried until they pass or the max retry limit is exceeded.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/active_record/connection_adapters/cockroachdb/transaction_manager.rb', line 11 def within_new_transaction( = {}) attempts = .fetch(:attempts, 0) super rescue ActiveRecord::SerializationFailure => error raise if attempts >= @connection.max_transaction_retries attempts += 1 sleep_seconds = (2 ** attempts + rand) / 10 sleep(sleep_seconds) within_new_transaction(.merge(attempts: attempts)) { yield } end |