What I want to do:
In a model.rb, in after_commit, I want to run rake task ts:reindex
ts:reindex is normally run with a rake ts:index
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you wish this rake code to run during the request cycle then you should avoid running rake via
systemor any of the exec family (including backticks) as this will start a new ruby interpreter and reload the rails environment each time it is called.Instead you can call the Rake commands directly as follows :-
Note: in Rails 4+, you’ll use
Rails.rootinstead ofRAILS_ROOT.And then just use
SomeModel.run_rake("ts:reindex")The key parts here are to
require rakeand make sure you load the file containing the task definitions.Most information obtained from http://railsblogger.blogspot.com/2009/03/in-queue_15.html