Pedro Côrte-Real
2006-Aug-11 15:05 UTC
[Mongrel] Running some code right before the app is available to users
I do some indexing using acts_as_ferret in a rails app. I need to do some preloading of the index''s sort fields so that the first request that sorts doesn''t take 5 minutes to complete. I tried sticking my preload code in config/environment.rb and that worked but it gets ran in rake migrations, tests, etc, when it''s not really needed. Is there anything specific to starting up to serve requests I could check for? Thanks, Pedro.
Zed Shaw
2006-Aug-11 17:51 UTC
[Mongrel] Running some code right before the app is available to users
On Fri, 2006-08-11 at 16:05 +0100, Pedro C?rte-Real wrote:> I do some indexing using acts_as_ferret in a rails app. I need to do > some preloading of the index''s sort fields so that the first request > that sorts doesn''t take 5 minutes to complete. I tried sticking my > preload code in config/environment.rb and that worked but it gets ran > in rake migrations, tests, etc, when it''s not really needed. Is there > anything specific to starting up to serve requests I could check for?You could put it in a mongrel.conf and just have Mongrel run it on start-up: mongrel_rails start -S mongrel.conf (Even though it ends in .conf it''s actually Ruby code that gets run inside the Configurator.) -- Zed A. Shaw http://www.zedshaw.com/ http://mongrel.rubyforge.org/ http://www.railsmachine.com/ -- Need Mongrel support?
Pedro Côrte-Real
2006-Sep-11 16:02 UTC
[Mongrel] Running some code right before the app is available to users
On 8/11/06, Zed Shaw <zedshaw at zedshaw.com> wrote:> You could put it in a mongrel.conf and just have Mongrel run it on > start-up: > > mongrel_rails start -S mongrel.conf > > (Even though it ends in .conf it''s actually Ruby code that gets run > inside the Configurator.)I''ve only now went to deploy the app and had to deal with this. The solution you gave works but not in the way I need it to. Mongrel will start listening on the port before rails starts up. The stuff I need to run takes a few minutes so I don''t want mongrel to be listening on the port before the script ends. Would you consider changing this order and making mongrel only start listening after rails has booted? That''s how webrick works. Thanks, Pedro.
Zed Shaw
2006-Sep-11 21:46 UTC
[Mongrel] Running some code right before the app is available to users
On Mon, 2006-09-11 at 17:02 +0100, Pedro C?rte-Real wrote:> On 8/11/06, Zed Shaw <zedshaw at zedshaw.com> wrote: > > You could put it in a mongrel.conf and just have Mongrel run it on > > start-up: > > > > mongrel_rails start -S mongrel.conf > > > > (Even though it ends in .conf it''s actually Ruby code that gets run > > inside the Configurator.) > > I''ve only now went to deploy the app and had to deal with this. The > solution you gave works but not in the way I need it to. Mongrel will > start listening on the port before rails starts up. The stuff I need > to run takes a few minutes so I don''t want mongrel to be listening on > the port before the script ends. Would you consider changing this > order and making mongrel only start listening after rails has booted? > That''s how webrick works.The port may be open but Mongrel isn''t processing any requests. They should queue up in the OS and then when rails is loaded Mongrel will process them. -- Zed A. Shaw http://www.zedshaw.com/ http://mongrel.rubyforge.org/ http://www.lingr.com/room/3yXhqKbfPy8 -- Come get help.
Pedro Côrte-Real
2006-Sep-12 09:45 UTC
[Mongrel] Running some code right before the app is available to users
On 9/11/06, Zed Shaw <zedshaw at zedshaw.com> wrote:> The port may be open but Mongrel isn''t processing any requests. They > should queue up in the OS and then when rails is loaded Mongrel will > process them.Yes, but that''s the problem. I run an apache proxying to mongrel and when mongrel is down it shows a custom error page saying that the app is not available. If mongrel starts listening on the port apache will try to connect and hang there until it timeouts instead of giving the error page to the user. Since mongrel can''t process any requests it would make more sense to only start listening on the port after rails boots. Pedro.
Pedro Côrte-Real
2006-Sep-13 11:30 UTC
[Mongrel] Running some code right before the app is available to users
On 9/12/06, Pedro C?rte-Real <pedro at pedrocr.net> wrote:> Since mongrel can''t process any requests it > would make more sense to only start listening on the port after rails > boots.Do you disagree with this? Is it very hard to do? Would you consider changing the behaviour to that? Pedro.
Zed Shaw
2006-Sep-13 13:16 UTC
[Mongrel] Running some code right before the app is available to users
On Wed, 2006-09-13 at 12:30 +0100, Pedro C?rte-Real wrote:> On 9/12/06, Pedro C?rte-Real <pedro at pedrocr.net> wrote: > > Since mongrel can''t process any requests it > > would make more sense to only start listening on the port after rails > > boots. > > Do you disagree with this? Is it very hard to do? Would you consider > changing the behaviour to that?I think Pedro that you might have to look for another solution before you try to get me to change the core of mongrel. I''m pretty sure there are plenty of other ways to do what you need and your requirements are particular to what you do. Not brushing you off, I just have to pick where I apply my time and this change would most likely break other established plugins and things. If you get desperate then crack open the mongrel_rails, throw your code at the top and call it mongrel_pedro_rails. That''s what I''d do. -- Zed A. Shaw http://www.zedshaw.com/ http://mongrel.rubyforge.org/ http://www.lingr.com/room/3yXhqKbfPy8 -- Come get help.