I''m looking for a way to have a controller pre-loaded at application startup and even in the development environment have it loaded just once. I''ll make it a bit more concrete. I''m in the process of writing a little plugin for interrogating the state of a Rails app. Among other things, it ties into request handling and provides a hook for gathering statistics. The code for calculating a statistic I''d like to define within a controller. Currently it looks like this class StatusController < ApplicationController include HealthCheck define_check :database_available do ActiveRecord::Base.connection != nil end define_statistic :request_count, :accumulator => [0] do | accumulator, *ignored| accumulator[0] += 1 end end With Rails working as it does, this code is only loaded when the status controller is accessed for the first time through a request. Only from then on are the defined statistics updated. In the development environment the accumulated values are forgotten again on the next request as classes are reloaded then. To circumvent these issues, I''d like to load this particular controller on startup and don''t have it reloaded again. Any suggestions on how to achieve this? Michael -- Michael Schuerig mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org http://www.schuerig.de/michael/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hello Michael, 2007/2/2, Michael Schuerig <michael@schuerig.de>:> To circumvent these issues, I'd like to load this particular controller > on startup and don't have it reloaded again. Any suggestions on how to > achieve this?Did you try to require or reference StatusController in environment.rb ? That would at least load the controller. Then, the reloading part... http://dev.rubyonrails.org/browser/trunk/activesupport/lib/active_support/dependencies.rb#L44 We have a way to unload constants, but not the reverse. Maybe this will help: #will_unload? http://dev.rubyonrails.org/browser/trunk/activesupport/lib/active_support/dependencies.rb#L288 Hope that helps ! -- François Beausoleil http://blog.teksol.info/ http://piston.rubyforge.org/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Friday 02 February 2007 18:39, Francois Beausoleil wrote:> Hello Michael,Hi Francois, thanks for helping.> 2007/2/2, Michael Schuerig <michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org>: > > To circumvent these issues, I''d like to load this particular > > controller on startup and don''t have it reloaded again. Any > > suggestions on how to achieve this? > > Did you try to require or reference StatusController in > environment.rb ? That would at least load the controller.Yes, either results in an exception as the ApplicationController, the superclass of StatusController, is not yet loaded and can''t be autoloaded either, apparently. I can require ''application'', of course, but that prevents reloading of ApplicationController even in the development environment, I gather.> Then, the reloading part...When I require StatusController in environment.rb, reloading is no longer a problem. But as I said above, I don''t like that I have to require ApplicationController in addition. This appears to be causing other mayhem, too. Just randomly clicking around in the app gave me an exception: ArgumentError "A copy of AuthenticatedSystem has been removed from the module tree but is still active!". I''m pretty sure this is related to the explicit require for ApplicationController, which includes AuthenticatedSystem. Michael -- Michael Schuerig mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org http://www.schuerig.de/michael/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hello Michael, 2007/2/2, Michael Schuerig <michael@schuerig.de>:> When I require StatusController in environment.rb, reloading is no > longer a problem. But as I said above, I don't like that I have to > require ApplicationController in addition. This appears to be causing > other mayhem, too. Just randomly clicking around in the app gave me an > exception: ArgumentError "A copy of AuthenticatedSystem has been > removed from the module tree but is still active!". I'm pretty sure > this is related to the explicit require for ApplicationController, > which includes AuthenticatedSystem.Instead of requiring "application", try to reference ApplicationController instead. Bye ! -- François Beausoleil http://blog.teksol.info/ http://piston.rubyforge.org/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Friday 02 February 2007 22:25, Francois Beausoleil wrote:> Hello Michael, > > 2007/2/2, Michael Schuerig <michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org>: > > When I require StatusController in environment.rb, reloading is no > > longer a problem. But as I said above, I don''t like that I have to > > require ApplicationController in addition. This appears to be > > causing other mayhem, too. Just randomly clicking around in the app > > gave me an exception: ArgumentError "A copy of AuthenticatedSystem > > has been removed from the module tree but is still active!". I''m > > pretty sure this is related to the explicit require for > > ApplicationController, which includes AuthenticatedSystem. > > Instead of requiring "application", try to reference > ApplicationController instead.This immediately results in an exception: "uninitialized constant ApplicationController (NameError)". I''ve tried it on a freshly generated project, too, and got the same exception. Michael -- Michael Schuerig mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org http://www.schuerig.de/michael/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---