/ ruby

Script/runner vz Rake tasks

When it comes to running Rails tasks the common question that comes to mind is whether to use script/runner or to call a rake task

script/runner long_running_task


rake long_running_task

To understand it better we need to understand how both works under the hood.

Whenever script/runner is called it boots the entire Rails

But on the other hand Rake task doesn't load the entire Rails app unless you tell it to by making the task depend on :environment, like this:

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

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

Manu S Ajith

Manu S Ajith

Tech Entrepreneur, dating Elixir, in long-term ❤️ w/ Ruby, had multiple one night stands w/ Go. Into functional paradigms DDD/CQRS/EventSourcing architecture these days. @manusajith on the interwebs

Read More