在 sidekiq worker 中需要一个模型文件

Requiring a model file in sidekiq worker

我在模型目录中有一个模型文件 'abc.rb'。

class Abc
  class << self
     //codes
   end
end

我想在 workers/bulk_uploader.rb 文件中调用 abc.rb 文件中的某些方法。我在调用 Abc.some_method 时出错。

我还需要文件 require '../models/abc.rb' 但我在 sidekiq 控制台中遇到错误

No such file to load -- ../models/abc (LoadError)

调用 Abc.some_method 时出现错误的原因之一是它未在 self. 上定义。

class Abc 
  def self.some_method
    puts "Meow"
  end

  def some_other_method
    puts "Woof"
  end
end

Abc.some_method           # => Meow
Abc.some_other_method     # => undefined method `some_other_method' for Abc:Class
Abc.new.some_other_method # => Woof

您不必要求任何模型文件。

https://github.com/mperham/sidekiq/wiki/Best-Practices

我犯了一个大错。我打错了方法名称。