我使用的是Rails 3.2,Mongoid 3.1.7,Moped 1.5.3和Resque 1.24.1
我反复得到" Moped :: Protocol :: Command失败,错误为nil" [1]我的Resque工作人员的错误。
摩托车回购中的This issue和this one让我觉得这可能是由于Resque forking,但他们都是关于旧版Moped而不是我使用的,并且我一直无法找到任何特定于配置Resque的特定信息,以便与Mongoid很好地协作。
如何解决Resque工作人员的错误?
[1]完整错误:
Exception: Moped::Errors::OperationFailure
Error: The operation: #<Moped::Protocol::Command @length=58 @request_id=3 @response_to=0 @op_code=2004 @flags=[] @full_collection_name="admin.$cmd" @skip=0 @limit=-1 @selector={:ismaster=>1} @fields=nil> failed with error nil
/shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/node.rb:99:in `block in command'
/shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/node.rb:600:in `[]'
/shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/node.rb:600:in `block (3 levels) in flush'
/shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/node.rb:599:in `map'
/shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/node.rb:599:in `block (2 levels) in flush'
/shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/node.rb:150:in `ensure_connected'
/shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/node.rb:595:in `block in flush'
/shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/node.rb:610:in `logging'
/shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/node.rb:594:in `flush'
/shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/node.rb:583:in `process'
/shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/node.rb:92:in `command'
/shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/node.rb:409:in `refresh'
/shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/cluster.rb:171:in `block in refresh'
/shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/cluster.rb:185:in `each'
/shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/cluster.rb:185:in `refresh'
/shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/cluster.rb:135:in `nodes'
/shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/cluster.rb:206:in `with_primary'
/shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/session/context.rb:108:in `with_node'
/shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/cursor.rb:137:in `load_docs'
/shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/cursor.rb:25:in `each'
/shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/query.rb:76:in `each'
/shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/query.rb:76:in `each'
/shared/bundle/ruby/2.2.0/gems/mongoid-3.1.7/lib/mongoid/contextual/mongo.rb:423:in `entries'
/shared/bundle/ruby/2.2.0/gems/mongoid-3.1.7/lib/mongoid/contextual/mongo.rb:423:in `check_existence'
/shared/bundle/ruby/2.2.0/gems/mongoid-3.1.7/lib/mongoid/contextual/mongo.rb:146:in `exists?'
/shared/bundle/ruby/2.2.0/gems/mongoid-3.1.7/lib/mongoid/contextual.rb:19:in `exists?'
/shared/bundle/ruby/2.2.0/gems/mongoid-3.1.7/lib/mongoid/validations/uniqueness.rb:273:in `validate_root'
/shared/bundle/ruby/2.2.0/gems/mongoid-3.1.7/lib/mongoid/validations/uniqueness.rb:52:in `block in validate_each'
/shared/bundle/ruby/2.2.0/gems/mongoid-3.1.7/lib/mongoid/validations/queryable.rb:23:in `with_query'
/shared/bundle/ruby/2.2.0/gems/mongoid-3.1.7/lib/mongoid/validations/uniqueness.rb:46:in `validate_each'
/shared/bundle/ruby/2.2.0/gems/activemodel-3.2.22/lib/active_model/validator.rb:153:in `block in validate'
/shared/bundle/ruby/2.2.0/gems/activemodel-3.2.22/lib/active_model/validator.rb:150:in `each'
/shared/bundle/ruby/2.2.0/gems/activemodel-3.2.22/lib/active_model/validator.rb:150:in `validate'
/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.22/lib/active_support/callbacks.rb:310:in `_callback_before_265'
/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.22/lib/active_support/callbacks.rb:418:in `_run__123721054543109017__validate__3207805434451540367__callbacks'
/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.22/lib/active_support/callbacks.rb:405:in `__run_callback'
/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.22/lib/active_support/callbacks.rb:385:in `_run_validate_callbacks'
/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.22/lib/active_support/callbacks.rb:81:in `run_callbacks'
/shared/bundle/ruby/2.2.0/gems/mongoid-3.1.7/lib/mongoid/callbacks.rb:130:in `run_callbacks'
/shared/bundle/ruby/2.2.0/gems/activemodel-3.2.22/lib/active_model/validations.rb:228:in `run_validations!'
/shared/bundle/ruby/2.2.0/gems/activemodel-3.2.22/lib/active_model/validations/callbacks.rb:53:in `block in run_validations!'
/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.22/lib/active_support/callbacks.rb:403:in `_run__123721054543109017__validation__3207805434451540367__callbacks'
/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.22/lib/active_support/callbacks.rb:405:in `__run_callback'
/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.22/lib/active_support/callbacks.rb:385:in `_run_validation_callbacks'
/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.22/lib/active_support/callbacks.rb:81:in `run_callbacks'
/shared/bundle/ruby/2.2.0/gems/mongoid-3.1.7/lib/mongoid/callbacks.rb:130:in `run_callbacks'
/shared/bundle/ruby/2.2.0/gems/activemodel-3.2.22/lib/active_model/validations/callbacks.rb:53:in `run_validations!'
/shared/bundle/ruby/2.2.0/gems/activemodel-3.2.22/lib/active_model/validations.rb:195:in `valid?'
/shared/bundle/ruby/2.2.0/gems/mongoid-3.1.7/lib/mongoid/validations.rb:84:in `valid?'
/releases/20160315172839/app/performers/garmin_receive_push.rb:11:in `block in perform'
/releases/20160315172839/app/performers/garmin_receive_push.rb:9:in `map'
/releases/20160315172839/app/performers/garmin_receive_push.rb:9:in `perform'
答案 0 :(得分:0)
这似乎有效。从我昨天的Resque工作人员中的30多个错误到过去18个小时内的0个错误。
添加到我的Resque配置:
Resque.before_fork do
::Mongoid.default_session.disconnect
end
我对这里究竟出了什么问题的描述并不完整。 Resque worker分叉子进程,然后子进程处理该作业,因此我当前的操作假设是类似于在链接问题中使用Unicorn和Passenger分叉描述的问题。