jimsynz / faye-rails

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

Faye.ensure_reactor_running! in an initializer #26

Closed nilbus closed 9 years ago

nilbus commented 11 years ago

Hi, I noticed your recent change to the README in which you recommended an initializer to run Faye.ensure_reactor_running!. I've actually tried this before with no luck. When I try to start a server in development mode, it just exits during the app startup like so.

$ rails server
=> Booting Thin
=> Rails 4.0.0.beta application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
>> Thin web server (v1.5.0 codename Knife)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop
Exiting

Have you gotten ensure_reactor_running! working in one of your own apps?

parndt commented 11 years ago

@nilbus did you get this working? If not could you please show us your initialiser?

nilbus commented 11 years ago

I never did get it working with ensure_reactor_running!, so I just didn't include that line and started the reactor manually when I needed to use it in the Rails console.

ghost commented 11 years ago

:+1: I have the same issue.

jimsynz commented 11 years ago

I wonder, is this specific to Rails 4?

ghost commented 11 years ago

I'm on Rails 3.2.13

film42 commented 11 years ago

Try adding config.threadsafe! to your development.rb and production.rb environments in /config/environments

ghost commented 11 years ago

No change.

bogdanRada commented 10 years ago

i have same issue

itkin commented 10 years ago

+1

fivetwentysix commented 10 years ago

+1

jimsynz commented 9 years ago

Okay. Here's the horrible way I solved this in MessageRocket:

# config/initializers/faye.rb

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

Rails.application.config.after_initialize do
  unless running_as_server?
    Faye.ensure_reactor_running!
  end
end
nomasprime commented 9 years ago

@jamesotron I'm not sure if this is the same issue but I'm getting the error eventmachine not initialized: evma_install_oneshot_timer (RuntimeError) when running Cucumber. I've added the initializer you suggested.

nomasprime commented 9 years ago

Never mind, it's because Cucumber doesn't load initialisers. To get it working I just needed to add Faye.ensure_reactor_running! to a support file, e.g., support/faye.rb.