On Oct 7, 2010, at 6:52 AM, [email protected] wrote:

> Anyone here have any experience with long running rake tasks on
> Heroku?

...

>  
> When the rake task crashes, it'll usually die with the message:
> ! Internal server error
> Other times it'll die with the message:

... snip ...

Yep.  I see this all the time too when I try to run a rake task from the 
command line for anything that takes a long time.

I have no answer for this other than to observe that the same code which causes 
this error when run via rake never seems to have a problem when run via cron:

desc 'tasks run automatically on Heroku'
task :cron => :environment do
   if Time.now.hour == 3
      LongRunner.new.run
   end
end

works fine where

desc 'long running task'
task :longrunner => :environment do
  LongRunner.new.run
end

heroku rake longrunner

gives the error condition you describe.

The other workaround to consider is to use Delayed::Job.  If your long runner 
can break up the work into individual bits that can be processed independently, 
put them on the job queue and run it that way.

class LongRunner
   def run
      MyModel.all.each{|m| m.send_later(:do_something)}
   end
end

Of course, this costs money (as does cron if you want it to run more often than 
once per day).

Mike

-- 
You received this message because you are subscribed to the Google Groups 
"Heroku" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/heroku?hl=en.

Reply via email to