# Initializing a Scheduler

**URL:** <https://www.ruby-forum.com/t/initializing-a-scheduler/103485>\
**Category:** Rails\
**Created:** [May 6, 2007, 10:13pm UTC](https://www.ruby-forum.com/t/initializing-a-scheduler/103485 "2007-05-06T22:13:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lee\_Faus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/db5fbb/32.png) [@Lee\_Faus](https://www.ruby-forum.com/u/Lee_Faus)\
**Post date:** [May 6, 2007, 10:13pm UTC](https://www.ruby-forum.com/t/initializing-a-scheduler/103485/1 "2007-05-06T22:13:06Z")

</div>

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:

```auto
config.after_initialize do
  cron = StartCron.new
  cron.run
end
```

I get this error when I start WEBrick…

```auto
=> 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

```auto
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
