Rails eventmachine не инициализирован evma_install_oneshot_timer

Я использую Rails 4.1.1, Thin 1.6.2, Redis 2.8.9Hiredis водитель) и faye-rails драгоценный камень.

я использую faye-rails подписаться на изменения на несколько моделей, и я использую Redis для других (не связанных) вещей.

Когда я пытался позвонить create на faye-observed модель (скажем, Apple), он выдает ошибку, как это:

2.1.1 :001 > Apple.create
   (0.1ms)  BEGIN
  SQL (0.4ms)  INSERT INTO `apples` (`created_at`, `updated_at`) VALUES ('2014-06-01 17:26:54', '2014-06-01 17:26:54')
   (7.6ms)  ROLLBACK
RuntimeError: eventmachine not initialized: evma_install_oneshot_timer
    from /home/david/.rvm/gems/ruby-2.1.1/gems/eventmachine-1.0.3/lib/eventmachine.rb:323:in `add_oneshot_timer'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/eventmachine-1.0.3/lib/eventmachine.rb:323:in `add_timer'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/eventmachine-1.0.3/lib/em/timers.rb:12:in `initialize'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/eventmachine-1.0.3/lib/em/deferrable.rb:173:in `new'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/eventmachine-1.0.3/lib/em/deferrable.rb:173:in `timeout'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/faye-1.0.1/lib/faye/protocol/envelope.rb:11:in `initialize'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/faye-1.0.1/lib/faye/protocol/client.rb:357:in `new'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/faye-1.0.1/lib/faye/protocol/client.rb:357:in `transport_send'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/faye-1.0.1/lib/faye/protocol/client.rb:346:in `block in send'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/faye-1.0.1/lib/faye/protocol/extensible.rb:23:in `call'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/faye-1.0.1/lib/faye/protocol/extensible.rb:23:in `pipe_through_extensions'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/faye-1.0.1/lib/faye/protocol/client.rb:343:in `send'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/faye-1.0.1/lib/faye/protocol/client.rb:92:in `handshake'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/faye-1.0.1/lib/faye/protocol/client.rb:131:in `connect'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/faye-1.0.1/lib/faye/protocol/client.rb:270:in `publish'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/faye-rails-2.0.0/lib/faye-rails/controller.rb:45:in `publish'
... 27 levels...
    from /home/david/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:219:in `within_new_transaction'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.1/lib/active_record/transactions.rb:208:in `transaction'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.1/lib/active_record/transactions.rb:326:in `with_transaction_returning_status'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.1/lib/active_record/transactions.rb:268:in `block in save'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.1/lib/active_record/transactions.rb:283:in `rollback_active_record_state!'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.1/lib/active_record/transactions.rb:267:in `save'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.1/lib/active_record/persistence.rb:34:in `create'
    from (irb):1
    from /home/david/.rvm/gems/ruby-2.1.1/gems/railties-4.1.1/lib/rails/commands/console.rb:90:in `start'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/railties-4.1.1/lib/rails/commands/console.rb:9:in `start'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:69:in `console'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/railties-4.1.1/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

Обратите внимание на RuntimeError: eventmachine not initialized: evma_install_oneshot_timer,

Ошибка чередуется между этим, и ArgumentError: wrong number of arguments (0 for 2..3),

После некоторого времени копания ошибка возникает только тогда, когда я пытаюсь сохранить наблюдаемую модель.

Любая помощь будет с благодарностью.

2 ответа

Я использую этот код с Фэй

$faye = Faye::Client.new('http://localhost/faye')
class Wrapper
    def self.publish(text)
       run_event_machine
        $faye.publish("/base", text)
    end

    def self.run_event_machine
        Thread.new { EM.run } unless EM.reactor_running?
        Thread.pass until EM.reactor_running?
    end
end

а когда нужно отправить данные просто:

Wrapper.publush("the truth is out there")

Вы пытаетесь вызвать Фэй (и EventMachine) из консоли rails. Консоль Rails не запускает EventMachine, а только веб-сервер. Если вам это нужно, вы должны использовать: Faye.ensure_reactor_running! в рельсах консольных или граблей задач.

Другие вопросы по тегам