views:

66

answers:

2

I have a controller action that generates a number of excel reports, this takes about 10 minutes to do. Sometimes I call it from my webapp, which is why it is an action.

But I also want to create a rake task to run this, so I can schedule it to automatically run once a night.

Any way to do this?

+1  A: 

Can you handle the report generation from your models? Models should be doing most of the work anyway and can be accessed from Rake tasks:

task :reports => :environment do
  ...
  # Do stuff with your models.
end
John Topley
I don't think so, I need to render XML templates to generate the excel reports
Janak
+1  A: 

I think you'll have to move your code into your model. Since it's bad to put knowledge about output rendering in models, I'd suggest putting all the business logic and data manipulation in the model, but then put the rendering code in your rake task. That would make the rake task analogous to the controller used on the web - maintaining separation of concerns.

You can look at ActionView::Base and work from there to figure out how to trigger rendering of templates.

edebill