为什么我会预期......定义ScheduledJob?

时间:2013-03-18 14:40:04

标签: ruby-on-rails ruby-on-rails-3

我有一个这样的课程

class RecurringJob
  include ScheduledJob

  run_every 1.hours

  def perform
    puts "perform job"
  end
end

我收到错误说:

  

预期D:/ASM/source/app/lib/jobs/scheduled_job.rb来定义ScheduledJob

文件定义是这样的:

module Delayed
 module ScheduledJob

def self.included(base)
  base.extend(ClassMethods)
  base.class_eval do
    @@logger = Delayed::Worker.logger
    cattr_reader :logger
  end
end
    ....

 end
end

错误是什么意思?这不是定义吗?

修改

我必须知道,这个类是在rake任务中定义的(除了类之外它是空的,我不知道是否允许)。

更详细的错误:

Expected D:/ASM/source/app/lib/jobs/scheduled_job.rb to define ScheduledJob
D:/Software/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:503:in `load_missing_constant'
D:/Software/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:192:in `block in const_missing'
D:/Software/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:190:in `each'
D:/Software/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:190:in `const_missing'
D:/Software/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:514:in `load_missing_constant'
D:/Software/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:192:in `block in const_missing'
D:/Software/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:190:in `each'
D:/Software/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:190:in `const_missing'
D:/ASM/source/app/lib/tasks/sandbox.rake:29:in `<class:RecurringJob>'
D:/ASM/source/app/lib/tasks/sandbox.rake:28:in `block in <top (required)>'

1 个答案:

答案 0 :(得分:1)

Rails遵循非常严格的命名约定,包括lib文件。

如果要在Delayed模块中定义ScheduledJob模块,则必须将文件命名为/lib/delayed/scheduled_job.rb

这将使Rails的期望与你的命名相匹配。