I have a need for a scheduler to run from inside of my rails
application. I am familiar with Java (J2EE) and new to Ruby. In Java I
would have used a framework called Quartz. I would have created a
servlet and in the init method started up the Quartz framework. I have
created a new Ruby class and called it StartCron.rb in the Components
folder of my Rails app. I have been playing with the development.rb
file to test my class. I have done this:
config.after_initialize do
cron = StartCron.new
cron.run
end
I get this error when I start WEBrick…
=> Booting WEBrick...
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:477:in
`const_missing': uninitialized constant Rails::Initializer::StartCron
(NameError)
from
script/../config/../config/environments/development.rb:24:in
`load_environment'
from
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/initializer.rb:335:in
`after_initialize'
from
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/initializer.rb:114:in
`process'
from
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/initializer.rb:43:in
`run'
Any help would be appreciated.
Here is the StartCron.rb file
require "rubygems"
require 'openwfe/util/scheduler'
class StartCron
def StartCron.run
OpenWFE.scheduler = Scheduler.new
OpenWFE.scheduler.start
# Simple usage
OpenWFE.scheduler.schedule_every('2s') { p 'every 2 seconds' }
OpenWFE.scheduler.join
end
end
This runs fine standalone.
Lee