Sidekiq / redis与websocket_rails冲突:eventmachine未初始化:evma_connect_to_server

时间:2013-09-15 14:45:30

标签: ruby-on-rails websocket redis eventmachine sidekiq

我正在使用sidekiq (2.13.1)(请参阅依赖项here),websocket-rails (0.6.2)(请参阅依赖项here)和redis-semaphore (0.2.1)(请参阅依赖项here

sidekiq已在我的应用程序中运行了很长时间,但在安装websocket-rails后,我无法再执行sidekiq作业了。它们都崩溃了这个堆栈跟踪:

2013-09-15T13:15:17Z 12682 TID-ouvinq47w INFO: Sidetiq::Clock start
2013-09-15T13:15:19Z 12682 TID-ouvinq47w INFO: Booting Sidekiq 2.13.1 using redis://localhost:6379/0 with options {}
2013-09-15T13:15:19Z 12682 TID-ouvinq47w INFO: Running in ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]
2013-09-15T13:15:19Z 12682 TID-ouvinq47w INFO: See LICENSE and the LGPL-3.0 for licensing details.
2013-09-15T13:15:19Z 12682 TID-ouvinq47w INFO: Starting processing, hit Ctrl-C to stop
2013-09-15T13:15:20Z 12682 TID-ouvjitprc EvaluationsJob JID-7a108bea6da948aee5f43a99 INFO: start
2013-09-15T13:15:20Z 12682 TID-ouvjitprc EvaluationsJob JID-7a108bea6da948aee5f43a99 INFO: fail: 0.003 sec
2013-09-15T13:15:20Z 12682 TID-ouvjitprc WARN: {"retry"=>false, "queue"=>"default", "class"=>"EvaluationsJob", "args"=>["518f599683c336fb87000003"], "jid"=>"7a108bea6da948aee5f43a99", "enqueued_at"=>1379250920.38564}
2013-09-15T13:15:20Z 12682 TID-ouvjitprc WARN: eventmachine not initialized: evma_connect_to_server
2013-09-15T13:15:20Z 12682 TID-ouvjitprc WARN: /Users/john/.rvm/gems/ruby-2.0.0-p247/gems/eventmachine-1.0.3/lib/eventmachine.rb:664:in `connect_server'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/eventmachine-1.0.3/lib/eventmachine.rb:664:in `bind_connect'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/eventmachine-1.0.3/lib/eventmachine.rb:640:in `connect'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-3.0.4/lib/redis/connection/synchrony.rb:72:in `connect'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-3.0.4/lib/redis/client.rb:271:in `establish_connection'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-3.0.4/lib/redis/client.rb:69:in `connect'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-3.0.4/lib/redis/client.rb:290:in `ensure_connected'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-3.0.4/lib/redis/client.rb:177:in `block in process'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-3.0.4/lib/redis/client.rb:256:in `logging'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-3.0.4/lib/redis/client.rb:176:in `process'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-3.0.4/lib/redis/client.rb:84:in `call'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-3.0.4/lib/redis.rb:870:in `block in getset'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-3.0.4/lib/redis.rb:36:in `block in synchronize'
/Users/john/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-3.0.4/lib/redis.rb:36:in `synchronize'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-3.0.4/lib/redis.rb:869:in `getset'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-semaphore-0.2.1/lib/redis/semaphore.rb:26:in `exists_or_create!'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/redis-semaphore-0.2.1/lib/redis/semaphore.rb:48:in `lock'
/Users/john/my_app/app/jobs/evaluations_job.rb:9:in `perform'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/processor.rb:48:in `block (3 levels) in process'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/middleware/chain.rb:115:in `call'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/middleware/chain.rb:115:in `block in invoke'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-failures-0.2.1/lib/sidekiq/failures/middleware.rb:10:in `call'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/middleware/chain.rb:117:in `block in invoke'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidetiq-0.3.6/lib/sidetiq/middleware.rb:13:in `call'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/middleware/chain.rb:117:in `block in invoke'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/middleware/server/active_record.rb:6:in `call'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/middleware/chain.rb:117:in `block in invoke'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/middleware/server/retry_jobs.rb:62:in `call'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/middleware/chain.rb:117:in `block in invoke'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/middleware/server/logging.rb:11:in `block in call'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/logging.rb:22:in `with_context'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/middleware/server/logging.rb:7:in `call'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/middleware/chain.rb:117:in `block in invoke'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/middleware/chain.rb:120:in `call'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/middleware/chain.rb:120:in `invoke'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/processor.rb:47:in `block (2 levels) in process'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/processor.rb:102:in `stats'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/processor.rb:46:in `block in process'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/processor.rb:83:in `do_defer'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-2.13.1/lib/sidekiq/processor.rb:37:in `process'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.14.1/lib/celluloid/calls.rb:25:in `public_send'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.14.1/lib/celluloid/calls.rb:25:in `dispatch'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.14.1/lib/celluloid/calls.rb:125:in `dispatch'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.14.1/lib/celluloid/actor.rb:326:in `block in handle_message'
/Users/john/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.14.1/lib/celluloid/tasks.rb:42:in `block in initialize'

我的问题与this Github issue有关,但我的版本为websocket-rails (0.6.2),高于应该处理此问题的websocket-rails (0.2.1)

堆栈跟踪指的是我的sidekiq工作:

## jobs/evaluations_job.rb

class EvaluationsJob
  include Sidekiq::Worker
  sidekiq_options :retry => false

  def perform(user_id)
    s = Redis::Semaphore.new("perform_evaluations_for_#{user_id}".to_sym, redis: NonBlockingRedis.new(connection: "localhost"))

    if s.lock(-1)  # => THIS IS evaluations_job.rb:9 WHERE IT ALL BREAKS...
      ...
    end
  end
end

我正在使用sidekiqwebsocket-rails的标准设置,但由于我不太确定这个问题的根源是什么,因此我将sidetiq个配置文件包含在我的问题(我正在使用sidetiq启动的工作来开始所有其他工作):

## config/initializers/sidetiq.rb

Sidekiq.configure_server do |config|
  require 'non_blocking_redis'
  Sidetiq::Clock.start!
end

1 个答案:

答案 0 :(得分:5)

我相信这可能是解决问题的解决方案

https://github.com/websocket-rails/websocket-rails/issues/29

$redis = Redis.new(:host => host, :port => port, :driver => :hiredis)