Sunday, March 15, 2009

Calling RAKE tasks

The syntax for calling a Rake task within rails env,


If you need to call a rake task from a standalone ruby script, then do remember to include 'rake' files.

Bellow I have provided an usage on how to call a RAKE task from a rufus scheduler script.

My scheduler script is placed inside /lib folder

Also the script will fail to locate your rake task if just call a RAKE method without loading the RAKE file ( the .rake file in which you have your tasks defined ).

So, make sure you load your rake task files.

require 'rubygems'
require 'rake'
require 'rufus/scheduler'

load File.join( RAILS_ROOT, 'lib',
'tasks', 'my_task.rake')

scheduler = Rufus::Scheduler.start_new

scheduler.cron("0 17 * * 0") do

This when triggered will call 'delete_order_files' task defined in a .rake file called MY_TASK.RAKE having namespace 'MAINTENANCE'

1 comment:

Anonymous said... is very informative. The article is very professionally written. I enjoy reading every day.
bad credit personal loan
canadian payday loans