I use whenever to call rake tasks throughout the day, but each task launches a new Rails environment. How can I run tasks throughout the day without relaunching Rails for each job?
Here’s what I came up with, would love to get some feedback on this…?
-
Refactor each rake task to instead be a method within the appropriate Model.
-
Use the delayed_job gem to assign low priority and ensure these methods run asynchronously.
-
Instruct whenever to call each Model.method instead of calling the rake task
Does this solution make sense? Will it help avoid launching a new Rails environment for each job? .. or is there a better way to do this?
—
Running Rails 3
Lots of good solutions to this problem, the one I eventually ended up integrating is as such:
whenevergem to runcommand 'curl mywebsite.com/model#method'I tried giving delayed_job a go but didn’t like the idea of running another Rails instance. My methods are not too server intensive, and the above solution allows me to utilize the already-running Rails environment.