我使用Sidekiq,以下是我的代码:
authentications_controller.rb:
def auth_provider auth, user
....
....
Facebook.loop_import fb_user, 'POST', user
end
Facebook.rb:
def self.loop_import(fb_user, type, user)
fb_user.posts({:locale => user.language}).each do |post|
p = Post.where(:id_ref_facebook => post.raw_attributes['id'].to_s).first
if p.blank?
#self.import post, user
RegistrationsWorker.perform_async(post.raw_attributes['id'])
else
self.update post, user, p
end
end if type == 'POST'
end
应用程序/工人/ registrations_worker.rb:
class RegistrationsWorker
include Sidekiq::Worker
def perform p_id
Rails.logger.info '--------------------------------------------------'
Rails.logger.info p_id
Rails.logger.info '--------------------------------------------------'
end
end
我在sidekiq终端尝试注册时有这个结果:
2014-08-06T16:18:25.541Z 14818 TID-ige3o WARN: {"retry"=>true, "queue"=>"default", "class"=>"RegistrationsWorker", "args"=>["1587189554_10203486498754922"], "jid"=>"3299251e473686b00b027b7b", "enqueued_at"=>1407341905.534449}
2014-08-06T16:18:25.542Z 14818 TID-ige3o WARN: uninitialized constant RegistrationsWorker
2014-08-06T16:18:25.542Z 14818 TID-ige3o WARN: /usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.0/lib/active_support/inflector/methods.rb:238:in `const_get'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.0/lib/active_support/inflector/methods.rb:238:in `block in constantize'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.0/lib/active_support/inflector/methods.rb:236:in `each'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.0/lib/active_support/inflector/methods.rb:236:in `inject'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.0/lib/active_support/inflector/methods.rb:236:in `constantize'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.0/lib/active_support/core_ext/string/inflections.rb:66:in `constantize'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidekiq-3.2.1/lib/sidekiq/processor.rb:46:in `process'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/celluloid-0.15.2/lib/celluloid/calls.rb:25:in `public_send'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/celluloid-0.15.2/lib/celluloid/calls.rb:25:in `dispatch'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/celluloid-0.15.2/lib/celluloid/calls.rb:122:in `dispatch'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/celluloid-0.15.2/lib/celluloid/actor.rb:322:in `block in handle_message'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/celluloid-0.15.2/lib/celluloid/actor.rb:416:in `block in task'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/celluloid-0.15.2/lib/celluloid/tasks.rb:55:in `block in initialize'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/celluloid-0.15.2/lib/celluloid/tasks/task_fiber.rb:13:in `block in create'
2014-08-06T16:18:25.547Z 14818 TID-11ila4 WARN: {"retry"=>true, "queue"=>"default", "class"=>"RegistrationsWorker", "args"=>["1587189554_10203485726855625"], "jid"=>"33eec574e1dad7f27eb78862", "enqueued_at"=>1407341905.5392146}
2014-08-06T16:18:25.550Z 14818 TID-11ila4 WARN: uninitialized constant RegistrationsWorker
答案 0 :(得分:2)
每次修改后重新启动sidekiq。
答案 1 :(得分:-2)
好吧我重启sidekiq并且队列没问题;
现在我改变了这段代码:
class RegistrationsWorker
include Sidekiq::Worker
def perform p_id
Rails.logger.info '--------------------------------------------------'
Rails.logger.info p_id
Rails.logger.info '--------------------------------------------------'
end
end
在:
class RegistrationsWorker
include Sidekiq::Worker
def perform p_id
@post = Post.new();
@post.save(:validate => false)
end
end
但也不写在mongoDB数据库中;
控制台中的消息全部开始并完成;