简体   繁体   中英

Rails help clockwork error: Exception NameError -> uninitialized constant Delayed::Job

When I run my clockwork I get this error:

C:\Rails\konkurranceportalen>bundle exec clockwork lib/clock.rb
Starting clock for 1 events: [ statistik ]
Triggering statistik
Exception NameError -> uninitialized constant Delayed::Job
   lib/clock.rb:6:in `block in <top (required)>'
   C:/Ruby192/lib/ruby/gems/1.9.1/gems/clockwork-0.2.3/lib/clockwork.rb:27:in `c
all'
   C:/Ruby192/lib/ruby/gems/1.9.1/gems/clockwork-0.2.3/lib/clockwork.rb:27:in `r
un'
   C:/Ruby192/lib/ruby/gems/1.9.1/gems/clockwork-0.2.3/lib/clockwork.rb:96:in `b
lock in tick'
   C:/Ruby192/lib/ruby/gems/1.9.1/gems/clockwork-0.2.3/lib/clockwork.rb:94:in `e
ach'
   C:/Ruby192/lib/ruby/gems/1.9.1/gems/clockwork-0.2.3/lib/clockwork.rb:94:in `t
ick'
   C:/Ruby192/lib/ruby/gems/1.9.1/gems/clockwork-0.2.3/lib/clockwork.rb:80:in `b
lock in run'
   C:/Ruby192/lib/ruby/gems/1.9.1/gems/clockwork-0.2.3/lib/clockwork.rb:79:in `l
oop'
   C:/Ruby192/lib/ruby/gems/1.9.1/gems/clockwork-0.2.3/lib/clockwork.rb:79:in `r
un'
   C:/Ruby192/lib/ruby/gems/1.9.1/gems/clockwork-0.2.3/bin/clockwork:20:in `<top
 (required)>'
   C:/Ruby192/lib/ruby/gems/1.9.1/bin/clockwork:19:in `load'
   C:/Ruby192/lib/ruby/gems/1.9.1/bin/clockwork:19:in `<main>'

My clock.rb in lib folder:

require 'rubygems'
require 'clockwork'
include Clockwork

every(2.minutes, 'statistik') { Delayed::Job.enqueue(Scraper.new) }

I have changed my clock.rb to:

require 'clockwork'
require 'delayed_job'
include Clockwork

every(2.minutes, 'statistik') { Delayed::Job.enqueue(Scraper.new) 

Then I get this error:

C:\Rails\konkurranceportalen>bundle exec clockwork lib/clock.rb
Starting clock for 1 events: [ statistik ]
Triggering statistik
Exception NameError -> uninitialized constant Delayed::Job
   lib/clock.rb:5:in `block in <top (required)>'
   C:/Ruby192/lib/ruby/gems/1.9.1/gems/clockwork-0.2.3/lib/clockwork.rb:27:in `c
all'
   C:/Ruby192/lib/ruby/gems/1.9.1/gems/clockwork-0.2.3/lib/clockwork.rb:27:in `r
un'
   C:/Ruby192/lib/ruby/gems/1.9.1/gems/clockwork-0.2.3/lib/clockwork.rb:96:in `b
lock in tick'
   C:/Ruby192/lib/ruby/gems/1.9.1/gems/clockwork-0.2.3/lib/clockwork.rb:94:in `e
ach'
   C:/Ruby192/lib/ruby/gems/1.9.1/gems/clockwork-0.2.3/lib/clockwork.rb:94:in `t
ick'
   C:/Ruby192/lib/ruby/gems/1.9.1/gems/clockwork-0.2.3/lib/clockwork.rb:80:in `b
lock in run'
   C:/Ruby192/lib/ruby/gems/1.9.1/gems/clockwork-0.2.3/lib/clockwork.rb:79:in `l
oop'
   C:/Ruby192/lib/ruby/gems/1.9.1/gems/clockwork-0.2.3/lib/clockwork.rb:79:in `r
un'
   C:/Ruby192/lib/ruby/gems/1.9.1/gems/clockwork-0.2.3/bin/clockwork:20:in `<top
 (required)>'
   C:/Ruby192/lib/ruby/gems/1.9.1/bin/clockwork:19:in `load'
   C:/Ruby192/lib/ruby/gems/1.9.1/bin/clockwork:19:in `<main>'

My scraper.rb in lib folder:

class Scraper
require 'mechanize'
def iqmedier
    #SOME CODE

  end

def mikkelsen
#SOME CODE

   end
def orville
   #SOME CODE
   end
end

I'm not actually familiar with ClockWork, but don't you need to add a "require 'delayed_job'" at the top of clock.rb? You may also need to install the delayed_job gem.

That said, if you're running with 'bundle exec', you ought to be using a Gemfile to manage this, and you shouldn't be requiring rubygems in clock.rb.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM