ActiveRecord::DeadlockRetry
Retries a transaction when a deadlock exception is returned from the database. Currently works with MySQL.
Installation
Add this line to your application's Gemfile:
gem 'activerecord-deadlock_retry'
And then execute:
$ bundle
Or install it yourself as:
$ gem install activerecord-deadlock_retry
Usage
ActiveRecord::DeadlockRetry.transaction do
# Your possibly deadlocking code here
end
ActiveRecord::DeadlockRetry.transaction
optionally takes an options hash with
the following options:
:class
- Classtransaction
(or:method
) is called on. Defaults toActiveRecord::Base
.:method
- Method to call on:class
(orActiveRecord::Base
). Defauls totransaction
.:retries
- Number of retries. Defaults to3
.