我有一個Rails 3.2的應用程序瘦服務器上,並在application.rb中運行,我想談談EventMachine的:Rails中後新的線程上運行EventMachine的是用薄裝
# application.rb
config.after_initialize do
if ENV['EM']
EM.run do
host = '0.0.0.0'
port = 3001
# hit Ctrl + C to 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 to stop."
end
end
end
SomeModule具有取決於Rails代碼正在加載。這就是爲什麼我把它放在after_initialize塊中而不是在初始化器中。現在
當我開始我的服務器(與rails s
)我的輸出看起來不錯:
=> Booting Thin
=> Rails 3.2.13 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
EventMachine running on 0.0.0.0:3001. Ctrl + C to stop.
但是,當我走在我的瀏覽器到localhost我得到了204 No Content
響應。
我能想到的幾件事情,導致這一點,但不是一個解決方案:)
- 也許我開始在同一個線程阻塞Rails應用程序的EventMachine的。但薄應該處理這個權利?
- 也許我應該以不同的方式啓動我的服務器,但如何呢?
有關[EventMachine github wiki]的更多信息(https://github.com/eventmachine/eventmachine/wiki/FAQ#does-em-work-with-other-ruby-threads-running) – thinkOfaNumber