Nicholas Thomas
2010-Jan-12 13:48 UTC
[Backgroundrb-devel] Rails after_initialize block doesn''t seem to be run in the backgroundrb context
Hi all, Just had an interesting production failure while updating my Rails application - a bunch of code previously in config/environment.rb was put into config/initializers. That resulted in me having to wrap some code in config/environments/production.rb into an after_initialize do ... end block When backgroundrb was run against that code, the setup done in that after_initialize block wasn''t run, leading to a failure in several background jobs that required it. Two purposes for the email - firstly, a heads-up that this is a problem, in case anyone else ends up bashing their heads against it. Secondly, anyone know how to /fix/ this? I''ve worked around it for now by moving the wrapped code into config/environment.rb, after Rails::Initializer do... end, wrapped in an if RAILS_ENV=production do ... end block - which is hardly ideal, although it has the advantage of working for now... ;) /Nick
Adam Williams
2010-Jan-12 14:19 UTC
[Backgroundrb-devel] Rails after_initialize block doesn''t seem to be run in the backgroundrb context
Nick, I am convinced at this point that it''s time to move on to Delayed Job. For one thing, Engine Yard strongly discourages the use of backgroundrb, and will not allow it at all on their cloud servers. I have made a great deal of effort to have as little code as possible in the workers already (good design practice to put business work in models - backgroundrb is an implementation detail), so making the migration should be relatively easy. There are some strange behaviors in backgroundrb, like this, that make it quite frustrating (for instance, how in the world does one make the logging work??). Coupled with the lack of current development (understandable), it seems to make sense to move on to more supported/encouraged technology. I know that doesn''t help, but just in case you were considering the move already :) Adam Williams On Jan 12, 2010, at 8:48 AM, Nicholas Thomas wrote:> Hi all, > > Just had an interesting production failure while updating my Rails > application - a bunch of code previously in config/environment.rb was > put into config/initializers. That resulted in me having to wrap some > code in config/environments/production.rb into an after_initialize > do ... end block > > When backgroundrb was run against that code, the setup done in that > after_initialize block wasn''t run, leading to a failure in several > background jobs that required it. > > Two purposes for the email - firstly, a heads-up that this is a problem, > in case anyone else ends up bashing their heads against it. Secondly, > anyone know how to /fix/ this? I''ve worked around it for now by moving > the wrapped code into config/environment.rb, after Rails::Initializer > do... end, wrapped in an if RAILS_ENV=production do ... end block - > which is hardly ideal, although it has the advantage of working for > now... ;) > > /Nick > > _______________________________________________ > Backgroundrb-devel mailing list > Backgroundrb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/backgroundrb-devel