<img src=“https://travis-ci.org/j0hnds/ayl-rails.svg?branch=master” alt=“Build Status” />
ayl-rails¶ ↑
This gem partners with the ayl gem to allow you to configure your standard ActiveRecord after_* hooks to be asynchronous.
Just register this gem in your Gemfile like:
gem 'ayl-rails'
Then in your model, you can convert your after_* hooks to be asynchronous.
For example:
after_save :method # or, after_create :method # or, after_update :method
becomes
ayl_after_save :method #, ayl_after_create :method #, ayl_after_update :method
In addition, the callback definitions can be parameterized in a couple of different ways.
First, you can make the callbacks conditional in the same way that you can make standard ActiveRecord callbacks conditional:
ayl_after_create :method, :if => :should_it_be_called?
In this example, the method will only be invoked on create if the method “should_it_be_called?” responds with true. Alternatively, something like:
ayl_after_create :method, :unless => :should_it_be_called?
In this example, the method will only be invoked on create if the method “should_it_be_called? responds with false.
You can also specify message parameters to control how the asynchronous message is processed. For example,
ayl_after_create :method, :message_options => { :delay => 20 }
will request that the underlying queuing engine will delay processing of the message for 20 seconds.
Naturally, the two types of parameters can be combined for a callback:
ayl_after_create :method, :message_options => { :delay => 20 }, :unless => :it_should_not_be_called?
Contributing to ayl-rails¶ ↑
-
Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet
-
Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it
-
Fork the project
-
Start a feature/bugfix branch
-
Commit and push until you are happy with your contribution
-
Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
Copyright¶ ↑
Copyright © 2011-2015 j0hnds@gmail.com. See LICENSE.txt for further details.