Forum: Ruby on Rails Rake task vs script/runner

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9c0eebc506c56c64dc616cdf123fa671?d=identicon&s=25 Chris Chris (aboulafia)
on 2008-10-22 09:55
Hello, until now I allways used script/runner for running Rails cron
jobs

I wonder is there is any benefit (except not having any fake runner
model in the models directory) to use a rake task instead in lib/tasks

Thanks
4dd75353dff93de29b53a1ac890a1771?d=identicon&s=25 Karthi kn (karthikeyan7585)
on 2008-10-22 13:18
Christophe Gimenez wrote:
> Hello, until now I allways used script/runner for running Rails cron
> jobs


Hi,

I also want to use the script/runner to run the Rails cron jobs. But I
don't know how to do that. So can you please share the code here so that
i will get some ideas?


Thanks in advance...
9c0eebc506c56c64dc616cdf123fa671?d=identicon&s=25 Chris Chris (aboulafia)
on 2008-10-23 07:56
It's very simple, all you have to do is create a new model in
app/models, eg. runner.rb

class Runner
 def self.doIt()
 end
end

Then, launch it from the command line
script/runner Runner.doIt
or a cron task
ruby /somedir/script/runner Runner.doIt
85b7e4df5568ae8b16013f311f9e5283?d=identicon&s=25 Anil Galve (anilg)
on 2011-12-18 15:38
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.
This topic is locked and can not be replied to.