Running EventMachine in new Thread after Rails is loaded using Thin -


i have rails 3.2 app running on thin server , in application.rb want start eventmachine:

# application.rb  config.after_initialize   if env['em']     em.run       host = '0.0.0.0'       port = 3001        # hit ctrl + c stop       signal.trap("int")  { eventmachine.stop }       signal.trap("term") { eventmachine.stop }        eventmachine::start_server host, port, somemodule        puts "eventmachine running on #{host}:#{port}. ctrl + c stop."     end   end end 

somemodule has code depends on rails being loaded. that's why put in after_initialize block instead of in initializer.

now when start server (with rails s) output looks fine:

=> booting thin => rails 3.2.13 application starting in development on http://0.0.0.0:3000 => call -d detach => ctrl-c shutdown server eventmachine running on 0.0.0.0:3001. ctrl + c stop. 

but when go localhost in browser 204 no content response.

i can think of several things causes this, not solution :)

  • maybe i'm starting eventmachine on same thread blocking rails app. thin should handle right?
  • maybe should start server differently, how then?

after more googling found since i'm using thin don't need run eventmachine.

my after_initialize block looks this:

config.after_initialize   include somemodule end 

and in somemodule wrapped code in em.next_tick block or i'd "eventmachine not initialized: evma_connect_to_server (runtimeerror)" error.

using eventmachine in rails app thin way easier thought :)


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -