没有任何数据可供显示
开源项目社区 | 当前位置 : |
|
www.trustie.net/open_source_projects | 主页 > 开源项目社区 > asynchronous |
asynchronous
|
0 | 0 | 13 |
贡献者 | 讨论 | 代码提交 |
AynchronousNow you can make any method in one of your models asynchronous. For example,
class TestRecord < ActiveRecord::Base
after_save :an_alert
def an_alert
logger.info 'We could now asynchronously send an email to tons of people with this alert.'
end
asynchronous :an_alert
end
That's it, just install the plugin, add a 'QueuedMethods' table (follow my migration script), and add the 'asynchronous :symbol' part below where you declare the method you are making asynchronous. I've included a migration script in the db folder to use for the QueuedMethods table.
To process your queue just set up a cron job using the script runner:
'script/runner 'MethodQueue.process' -e production'
This is still in its first draft, but working under the conditions shown in the tests. Please feel free though to hack at it an make it better. I think it's a pretty useful tool. But a couple things I don't like:
1) What's the standard way these days to create a table a plugin depends on? Probably not in the install.rb in case there is a name conflict?
2) The 'asynchronous' part has to be declared below the method declaration. Is there anyway to make it agnostic of the method declaration location?
TestingIf you want to test, you need to have a test table for the test model setup in the database. I included a mysql.sql file to create that table in the test/fixtures dir. Then you can just run 'rake', in your RAILS_PROJ/vendor/plugins/asynchronous.
Major ThanksChris Eppstein provided a great patch that got rid of race condition the original plugin had. This makes it truly useful for most jobs people need something like this for. Thanks man!