We learned how to create Rake tasks in rails app. Next thing in process will be scheduling these tasks.
I opted for Rufu-Scheduler, mainly bcs it is quite simple to implement/configure
You can download the gem directly from
: http://gems.rubyforge.vm.bytemark.co.uk/gems/
There some good resources in net which describes usage of Rufus scheduler.
Like
:http://rufus.rubyforge.org/rufus-scheduler/
But some how I got myself into trouble in getting this to working ;(
Following are questions that bubbled in my mind while implementing Rufus.
>> Where do I put the scheduler code?
>> How will rails trigger my tasks, do I need to include something in my config. file?
I created a file in my /lib dir named myscheduler.rb, this contains the scheduler code and inorder to allow rails to load your rufus scheduler, you have to do
require ' myscheduler'
in environment.rb
My myscheduler.rb has
require 'rubygems'
require 'rake'
require 'rufus/scheduler'
load File.join( RAILS_ROOT, 'lib',
'tasks', 'mytasks.rake')
# Note include file containing your rake tasks
# Else you will get - Don’t know how to build
#task XXXXX’ error for the tasks you
#have defined
scheduler = Rufus::Scheduler.start_new
scheduler.every("1m") do
puts "Scheduler invoked"
end
restart the server and check for 'Scheduler invoked' in your CMD.
Got it ......... your half done with your scheduling, take a break ;)