Calling Rake from INSIDE the application

Hey there
I would like to know if I can call a rake task from inside my Rails App.
Something like

class MyModel < ActiveRecord::Base
after_save :run_task

def run_task
Rake.run(“my:little:task”)
end
end

This is the deal: I use thinking-sphinx and need to update a bunch of
data
through Model.update_all. But I would like sphinx to index it just after
I’m
done, by running rake ts:index.

Is that possible?

Thanks,
Dante

def run_task
result = %x(rake #{params[:rake_task]})
end

If you don’t want to hold the thread you can install the crontab gem
and install a new crontab with a ts:in or use background-fu and push
the job to the background…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs