Rails: when does + delayed_job optimize rake tasks?

I use rake tasks every time during the day, but each task launches a new Rails environment. How can I run tasks during the day without restarting Rails for each task?

Here is what I came up with, would like to get some feedback on this?

  • Reorganize each rake task instead of being a method in the appropriate model.

  • Use the delayed_job gem to assign a low priority and ensure that these methods execute asynchronously.

  • Configure when to invoke each Model.method instead of calling the rake command

Does this decision make sense? Did this avoid starting a new Rails environment for every job? .. or is there a better way to do this?

-

Launch Rails 3

+3
source share
3 answers

The many good solutions to this problem that I eventually completed with integration are as follows:

  • Moved my rake code to the appropriate models.
  • Added controller / routing code to call model methods from the browser.
  • Configured cronjob using whenevergem to runcommand 'curl mywebsite.com/model#method'

I tried giving delayed_job, but I didn't like the idea of ​​starting another Rails instance. My methods are not too intensive for the server, and the solution above allows me to use the already running Rails environment.

0
source

, , enqueuing delayed_jobs cron, delayed_job.

whenever, delayed_job. , , whenever cron output script, active_record delayed_job , rails. http://snippets.aktagon.com/snippets/257-How-to-use-ActiveRecord-without-Rails

clockwork.rb, , , cron for (enqueuing delayed_jobs): http://rubydoc.info/gems/clockwork/0.2.3/frames

delayed_jobs: https://gist.github.com/704047

+4

schedule.rb

require File.expand_path(File.dirname(__FILE__) + "/environment")

, .

0
source

All Articles