Sha256: 5425452749e2417eeabf142de5710e1b468ed7ec793281f0f71dd4a0eec05672
Contents?: true
Size: 948 Bytes
Versions: 7
Compression:
Stored size: 948 Bytes
Contents
# frozen_string_literal: true module ActiveRecord module ConnectionAdapters module CockroachDB module TransactionManagerMonkeyPatch # 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. def within_new_transaction(options = {}) attempts = options.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(options.merge(attempts: attempts)) { yield } end end end class TransactionManager prepend CockroachDB::TransactionManagerMonkeyPatch end end end
Version data entries
7 entries across 7 versions & 1 rubygems