Rake::Task[TASK_NAME].invoke
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.
USAGE
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
Rake::Task["maintenance:delete_order_files"].invoke
end
This when triggered will call 'delete_order_files' task defined in a .rake file called MY_TASK.RAKE having namespace 'MAINTENANCE'
1 comment:
railsblogger.blogspot.com is very informative. The article is very professionally written. I enjoy reading railsblogger.blogspot.com every day.
bad credit personal loan
canadian payday loans
Post a Comment