当我运行我的发条时,我收到了这个错误:
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>'
我在lib文件夹中的clock.rb:
require 'rubygems'
require 'clockwork'
include Clockwork
every(2.minutes, 'statistik') { Delayed::Job.enqueue(Scraper.new) }
我已将clock.rb更改为:
require 'clockwork'
require 'delayed_job'
include Clockwork
every(2.minutes, 'statistik') { Delayed::Job.enqueue(Scraper.new)
然后我收到此错误:
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>'
我在lib文件夹中的scraper.rb:
class Scraper
require 'mechanize'
def iqmedier
#SOME CODE
end
def mikkelsen
#SOME CODE
end
def orville
#SOME CODE
end
end
答案 0 :(得分:1)
我实际上并不熟悉ClockWork,但是你不需要在clock.rb的顶部添加一个“require'delayd_job'”吗?您可能还需要安装delayed_job gem。
也就是说,如果你使用'bundle exec'运行,你应该使用Gemfile来管理它,你不应该在clock.rb中要求rubygems。