特定的Sidekiq工作(三个中的一个)失败了:
NameError: uninitialized constant VerifiedReplacementRequestWorker
NewRelic报告中的堆栈回溯:
…ruby-2.2.4/gems/sidekiq-5.0.4/lib/sidekiq/processor.rb: 237:in `block in constantize'
…ruby-2.2.4/gems/sidekiq-5.0.4/lib/sidekiq/processor.rb: 236:in `each'
…ruby-2.2.4/gems/sidekiq-5.0.4/lib/sidekiq/processor.rb: 236:in `inject'
…ruby-2.2.4/gems/sidekiq-5.0.4/lib/sidekiq/processor.rb: 236:in `constantize'
…ruby-2.2.4/gems/sidekiq-5.0.4/lib/sidekiq/processor.rb: 137:in `block (5 levels) in dispatch'
…/rvm/gems/ruby-2.2.4/gems/sidekiq-5.0.4/lib/sidekiq.rb: 36:in `call'
…/rvm/gems/ruby-2.2.4/gems/sidekiq-5.0.4/lib/sidekiq.rb: 36:in `block in <module:Sidekiq>'
…ruby-2.2.4/gems/sidekiq-5.0.4/lib/sidekiq/processor.rb: 136:in `call'
…ruby-2.2.4/gems/sidekiq-5.0.4/lib/sidekiq/processor.rb: 136:in `block (4 levels) in dispatch'
…ruby-2.2.4/gems/sidekiq-5.0.4/lib/sidekiq/processor.rb: 215:in `stats'
查看来源,这与此代码相关:
@reloader.call do
klass = constantize(job_hash['class'.freeze])
worker = klass.new
worker.jid = job_hash['jid'.freeze]
@retrier.local(worker, job_hash, queue) do
yield worker
end
end
重新加载的大部分是由此完成的。
def constantize(str)
names = str.split('::')
names.shift if names.empty? || names.first.empty?
names.inject(Object) do |constant, name|
constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
end
end
问题是:为什么找不到代码?
我尝试过从Rails初始化程序手动要求Sidekiq作业类,甚至尝试从作业排队的代码。似乎没有找到这个特定的类,尽管有两个其他工作类似乎没有遇到此加载问题。
constantize
方法在哪里寻找代码?
这在暂存时失败,但在生产环境中似乎没有失败。开发内联Sidekiq工作,因此也没有证明问题。
寻找一些线索如何解决这个问题。
有问题的worker类的代码位于 app / workers 中的Rails中。我试过修改Rails的自动加载和急切的加载路径无济于事。