ruby-on-rails ruby ruby-on-rails-4 redis faye

ruby on rails - Rails eventmachine no inicializado evma_install_oneshot_timer



ruby-on-rails ruby-on-rails-4 (2)

Estoy utilizando Rails 4.1.1 , Thin 1.6.2 , Redis 2.8.9 (con el controlador Hiredis ) y la gema faye-rails .

Uso faye-rails para suscribir cambios en algunos modelos, y uso Redis para otras cosas (no relacionadas).

Cuando traté de llamar a create en un modelo faye-observed (digamos Apple), arroja un error como este:

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>''

Observe el RuntimeError: eventmachine not initialized: evma_install_oneshot_timer .

El error se alterna entre eso y ArgumentError: wrong number of arguments (0 for 2..3) .

Después de un tiempo de excavación, el error solo ocurre cuando intento guardar un Modelo observado.

Cualquier ayuda sería felizmente apreciada.


Está intentando llamar a Faye (y EventMachine) desde la consola de rieles. La consola de Rails no ejecuta EventMachine, solo lo hace el servidor web. Si lo necesita trabajando, debería usar: Faye.ensure_reactor_running! en la consola de rieles o tareas de rake.


Yo uso este código con Faye

$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

y cuando necesita enviar datos solo:

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