delayed_job: 'undefined method' error when using handle_asynchronously

坚强是说给别人听的谎言 提交于 2019-12-06 04:05:14

Your import is a class method, you should call handle_asynchronously on your model class name's singleton class:

You can use the metaclass trick to alias class methods:

class << self
   def import(file, store_id)
     CSV.foreach(file.path, headers: true) do |row|
      inventory_item = InventoryItem.find_or_initialize_by_upc_and_store_id(row[0], store_id)
      inventory_item.update_attributes(:price => row.to_hash["price"], :updated_at => "#{Time.now}")
     end
   end
  handle_asynchronously :import
end

Hope this helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!