ActiveJob 未初始化常量
ActiveJob uninitialized constant
我有一个关于 ActiveJob
的奇怪问题。
我正在从控制器执行以下句子:
ExportJob.set(wait: 5.seconds).perform([A series of parameters, basically strings and integers])
ExportJob.rb
require_relative 'blablabla/resource_manager'
class ExportJob < ActiveJob::Base
def perform
ResourceManager.export_process([A series of parameters, basically strings and integers])
end
end
当controller/action第一次执行时,过程正常,但第二次抛出错误:
uninitialized constant ExportJob::ResourceManager
奇怪的是,这不是我项目中唯一的工作,其他的都在毫无问题地执行。
我附上我的项目的一些信息:
development/production.rb
config.active_job.queue_adapter = :delayed_job
宝石文件:
gem 'delayed_job'
gem 'delayed_job_active_record'
任何线索都会对我有所帮助。
提前致谢!
常量在 Ruby 中没有全局作用域。常量在任何范围内都是可见的,但您必须指定要在何处找到常量。
Without ::
Ruby 在当前执行代码的词法范围内查找 ResourceManager
常量(即 ExportJob
class,所以看起来ExportJob::ResourceManager
).
以下应该有效(假设 ResourceManager
被定义为顶级常量(例如不嵌套在任何 module/class 下):
class ExportJob < ActiveJob::Base
def perform
::ResourceManager.export_process(*args)
end
end
我有一个关于 ActiveJob
的奇怪问题。
我正在从控制器执行以下句子:
ExportJob.set(wait: 5.seconds).perform([A series of parameters, basically strings and integers])
ExportJob.rb
require_relative 'blablabla/resource_manager'
class ExportJob < ActiveJob::Base
def perform
ResourceManager.export_process([A series of parameters, basically strings and integers])
end
end
当controller/action第一次执行时,过程正常,但第二次抛出错误:
uninitialized constant ExportJob::ResourceManager
奇怪的是,这不是我项目中唯一的工作,其他的都在毫无问题地执行。
我附上我的项目的一些信息:
development/production.rb
config.active_job.queue_adapter = :delayed_job
宝石文件:
gem 'delayed_job'
gem 'delayed_job_active_record'
任何线索都会对我有所帮助。
提前致谢!
常量在 Ruby 中没有全局作用域。常量在任何范围内都是可见的,但您必须指定要在何处找到常量。
Without ::
Ruby 在当前执行代码的词法范围内查找 ResourceManager
常量(即 ExportJob
class,所以看起来ExportJob::ResourceManager
).
以下应该有效(假设 ResourceManager
被定义为顶级常量(例如不嵌套在任何 module/class 下):
class ExportJob < ActiveJob::Base
def perform
::ResourceManager.export_process(*args)
end
end