Make Redmon a mountable Rack app#19
Conversation
Make Redmon a mountable Rack app
|
Thanks @romanbsd it works like a champ. |
|
It's possible to start the worker automatically, using something like this: require 'redmon/app'
require 'redmon/worker'
module Redmon
class Railtie < Rails::Railtie
config.before_configuration do
if EM.reactor_running?
Worker.new.run!
else
fork do
trap('INT') { EM.stop }
trap('TERM') { EM.stop }
EM.run { Worker.new.run! }
end
end
end
end
endThe downside is that it'll use a bit more memory, as the rails already loads some part of the framework until this point. |
|
@romanbsd can you elaborate a bit more please? I understand the Railtie hook but the memory (heap?) part I'm a little fuzzy on. Is it enough of a concern that I should consider refactoring the worker to use something like a Celluloid timer. Although it seems a little strange to mix an evented and threaded solution together when running outside of a Rails env. Also, is it bad practice for gems to start a reactor or spawn a thread when being used inside a Rails app? Perhaps it would be possible to mixin a strategy (EM or threaded) into the Worker. Thoughts? Thanks again for the input here. |
|
I don't think that a refactoring of the worker is needed. IMHO, the best possible solution would be to hack into the running app after it's started, so the same EM reactor as used by the "thin" webserver is utilized and there's no wasted memory (for another process). But I don't think that it's possible without a monkey patch to thin.
|
This change allows using Redmon alongside another Rack application, such as Rails.
It required to refactor the config handling.
I also updated the README for the usage examples.