开发者

Rails + Heroku :: rake task inside cron task

Questions

1) When runni开发者_如何学JAVAng cron tasks at Heroku, does Heroku have a time limit that cron tasks should last only X minutes or can the cron task run for whatever time it needs to complete processing?

2) To optimize my application, I want to move all my processing to batch mode. So I have lots of update queries. Basically that one Heroku cron file is getting messy. What can I do to clean up the code? Should I create multiple rake tasks and invoke the task tasks from the cron file?

2.1) If you agree with that then how do I invoke rake tasks from cron task? Let's say there are 3 independent rake tasks rake accounts:billing, rake accounts:collections, rake accounts:cleanup. How do I call them in cron file?


There aren't any time limits that I know of.

Using multiple tasks instead of one big cron task is a good idea. Not only is it easier to debug and maintain when they're separate but you can also easily run them individually when needed. And well factored code is a just a good idea all by itself.

Executing a task from another task is as simple as Rake::Task[task].execute. You'd have something like this:

desc 'Heroku cron job'
task :cron => :environment do
    %w{accounts:billing accounts:collections accounts:cleanup}.each do |task|
        Rake::Task[task].execute
    end
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜