Is it possible to have unicorn spawn a new worker when a request comes in, and only allow that child to service the one request? In development mode it would be nice if I could just save my changes and know that I will see them right away without having to HUP the server. thanks, -joe
Joseph McDonald <superjoe at gmail.com> wrote:> Is it possible to have unicorn spawn a new worker when a request comes > in, and only allow that child to service the one request? > > In development mode it would be nice if I could just save my changes > and know that I will see them right away without having to HUP the > server.Hi Joseph, Yes, just send SIGQUIT to yourself anywhere inside the application dispatch and it''ll defer the exit until your application is done processing. You should be able to just make it middleware like this: # name inspired by the "shotgun" gem class Unicorn::Shotgun < Struct.new(:app) def call(env) Process.kill(:QUIT, 0) app.call(env) end end -- Eric Wong
Joseph McDonald <superjoe at gmail.com> wrote:> On Tue, Dec 15, 2009 at 6:37 PM, Eric Wong <normalperson at yhbt.net> wrote: > > > Yes, just send SIGQUIT to yourself anywhere inside the application > > dispatch and it''ll defer the exit until your application is done > > processing. > > > > You should be able to just make it middleware like this: > > > > ?# name inspired by the "shotgun" gem > > ?class Unicorn::Shotgun < Struct.new(:app) > > ? ?def call(env) > > ? ? ?Process.kill(:QUIT, 0)^-- Oops, that should be a $$, not 0> > ? ? ?app.call(env) > > ? ?end > > ?end > > Thanks Eric, > I added that middleware, but now unicorn exits after servicing one > request. I''d like unicorn to keep running and fork off a new child if > a new request comes in. Is that possible?Yeah, just change the 0 to a $$ there, brain fart :x With that middleware, it should prefork a worker, but then kill it after every request (and a new one will be preforked). -- Eric Wong