Retries an operation on an ActiveRecord until no StaleObjectError is being raised.
<img src=“https://secure.travis-ci.org/neopoly/retryable_record.png?branch=master” alt=“Build Status” /> <img src=“https://badge.fury.io/rb/retryable_record.png” alt=“Gem Version” /> <img src=“https://codeclimate.com/github/neopoly/retryable_record.png” />
Gem | Source | Documentation
You can use retryable_record
in 3 different ways:
require 'retryable_record' RetryableRecord.retry(user) do user.username = "foo" user.save! end
require 'retryable_record/import' RetryableRecord(user) do user.username = "foo" user.save! end
require 'retryable_record' class User < ActiveRecord::Base include RetryableRecord end user = User.first user.retryable do user.username = "foo" user.save! end
ActiveRecord migration needs to support optimistic locking. See api.rubyonrails.org/classes/ActiveRecord/Locking/Optimistic.html
class CreateUsers < ActiveRecord::Migration def change create_table :users do |t| t.string :name t.integer :lock_version t.timestamps end end end
Inspired by
-
blog.codefront.net/2008/01/14/retrying-code-blocks-in-ruby-on-exceptions-whatever/
-
vision-media.ca/resources/ruby/better-ruby-retryable-method (broken)
-
Better example in README
-
Intergration test with ActiveRecord
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-
Send me a pull request. Bonus points for topic branches.