jimsynz / faye-rails

Simple Rails glue for the Faye messaging protocol.
MIT License
435 stars 79 forks source link

rake aborted! eventmachine not initialized: evma_install_oneshot_timer #73

Open deemytch opened 9 years ago

deemytch commented 9 years ago

Rails 4.2.0 ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux] thin 1.6.3

I got this error when creating/saving observed model in rake db:seed or in console. I have this in config/initializers/faye.rb I don't know where else do I need to check.

def running_as_server?
  Rails.const_defined?('Server') || defined?(::Rack::Handler::Thin)
end

Rails.application.config.after_initialize do
  unless running_as_server?
    puts "--Faye.ensure_reactor_running!"
    Faye.ensure_reactor_running!
  end
end

and in config/application.rb

config.middleware.delete Rack::Lock
config.middleware.use FayeRails::Middleware, mount: '/quick', :timeout => 25 do
    map '/registerapp/**' => ManageTabletsController
      # ... more mappings
      map :default => :block
    end

and in ManageTabletsController

class ManageTabletsController < FayeRails::Controller
  observe Device, :after_save do |r|
    #some code
  end
end
nomasprime commented 9 years ago

I'm having a similar problem with Rspec, I'm stumped too. Is @jamesotron out there?

nomasprime commented 9 years ago

https://github.com/stevegraham/em-rspec makes this error go away.

jimsynz commented 9 years ago

I think that recent versions of rspec-rails aren't running rails initializers on startup - I'd need to confirm that with @jonrowe however.

JonRowe commented 9 years ago

I think that recent versions of rspec-rails aren't running rails initializers on startup - I'd need to confirm that with @jonrowe however.

Only if Rails has, rspec-rails merely adapts the Rails test helpers for use with RSpec.

nomasprime commented 9 years ago

Thanks @jamesotron and @JonRowe for responding so quickly, rules out initializers. This article also helped, I'm new to event callback model but just about wrapped my head around it now.

leei commented 9 years ago

See my answer on StackOverflow for another approach.

clairezed commented 8 years ago

Hello @jamesotron, thanks for your work on FayeRails ! I'm running a similar problem in a rake task, launched via a cron. (RuntimeError) "eventmachine not initialized: evma_install_oneshot_timer".

The error isn't raised systematically.When it is, it happens when the tasks hits a line where a custom Controller (inheriting FayeRails::Controller) tries to publish a message.

My conf :

I have the same initializer as @deemytch, and I'm a bit lost regarding what I could do. The app is on production (the problem never popped while on dev) and I'm not into monkeypatching (as suggests @habitullence article). Would you have any clue on how to get rid of this error ?