Resque worker not recognizing the Rails Mongoid model
I am using resque in my application for delayed jobs, where i cant send emails & sms to bulk number of users asynchronously. And the data is stored in mongodb, mongoid is the ODM connects rails & mongo.
My mongoid model looks like this
class Item
  include Mongoid::Document
  include Geo::LocationHelper 
  field :name, :type => String
  field :desc, :type => String
  #resque queue name
  @queue = :item_notification
  #resque perform method
  def self.perform(item_id)
     @item = Item.find(item_id)
  end
end
I can able to add jobs to resque, i have verified using resque-web. Whenever i start an resque-worker
QUEUE=item_notification rake resque:work
i got the uninitialized constant Item , since i am using resque as rails gem and starting rake in rails root, i believe my mongoid models should be loaded.
After digging lot, i found that we can explicitly ask rake to load the environment by
  QUEUE=item_not开发者_StackOverflowification rake environment resque:work
but now also i got the same error uninitialized constant Item
can someone help me out?
and my
Actually, its a problem in dev environment. after adding this line to into resque.rake task file
# load the Rails app all the time
namespace :resque do
  puts "Loading Rails environment for Resque"
  task :setup => :environment
  ActiveRecord::Base.send(:descendants).each { |klass|  klass.columns }
end
it works fine
The code taken from GitHub-Resque-Wiki
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论