Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I have a Rails task: should I use script/runner or rake?

For ad hoc Rails tasks we have a few implementation alternatives, chief among which would seem to be:

script/runner some_useful_thing 

and:

rake some:other_useful_thing 

Which option should I prefer? If there's a clear favourite then when, if ever, should I consider using the other? If never, then why would you suppose it's still present in the framework without deprecation warnings?

like image 973
Mike Woodhouse Avatar asked Feb 26 '09 17:02

Mike Woodhouse


People also ask

What is task in Ruby on Rails?

Rake is a popular task runner for Ruby and Rails applications. For example, Rails provides the predefined Rake tasks for creating databases, running migrations, and performing tests. You can also create custom tasks to automate specific actions - run code analysis tools, backup databases, and so on.


1 Answers

The difference between them is that script/runner boots Rails whereas a Rake task doesn't unless you tell it to by making the task depend on :environment, like this:

task :some_useful_task => :environment do   # do some useful task end 

Since booting Rails is expensive, it might be worth skipping if you can avoid it.

Other than that, they are roughly equivalent. I use both, but lately I've used script/runner executing a script separately more.

like image 175
Luke Francl Avatar answered Sep 22 '22 13:09

Luke Francl