ActiveRecord3 deadlock retry
deadlock, mysql, ruby-on-rails-3
Solution
I didn't even know there was a plugin to do this :)
Here's what we use (but you have to wrap deadlock-prone queries in it yourself):
# Executes the given block +retries+ times (or forever, if explicitly given nil),
# catching and retrying SQL Deadlock errors.
def retry_lock_error(retries = 100, &block)
begin
yield
rescue ActiveRecord::StatementInvalid => e
if e.message =~ /Deadlock found when trying to get lock/ and (retries.nil? || retries > 0)
retry_lock_error(retries ? retries - 1 : nil, &block)
else
raise e
end
end
end
Problem
Are there any plugins for Rails 3 (or ActiveRecord 3) that replicate the old deadlock_retry plugin? Or, does that plugin still work with Rails 3?