Hi, I''m using Rails/AAF with Ferret 0.10.11, and my index occasionally (every few weeks, roughly) becomes corrupted. If the index is busted, until I rebuild it our users are unable to save anything. I get errors like the one below, and the save rolls back. My question is, is there any way to catch the error, and continue with the save even if the model isn''t indexed? What would be ideal is if i could have a catch the error, and have it send me a notification, which would solve two problems: the save would still happen so our users wouldn''t be impacted, and I would know exactly when the index had become corrupted, and could rebuild it. TIA for any help, John here''s the error i''m getting: Processing UserController#signup (for 72.227.101.170 at 2006-10-31 11:23:06) [POST] Session ID: 7f854fa9eaf95becbb9723a9bd48f9c2 Parameters: {"user"=>{"subscribe_to_newsletter"=>"0", "password_confirmation"=>"[FILTERED]", "terms"=>"1", "password"=>"[FILTERED]", "login"=>"jmcgrath", "email"=>"jmcgrath at whoi.edu"}, "commit"=>"Sign Up", "action"=>"signup", "controller"=>"user"} Unable to send confirmation E-Mail: Lock Error occured at <except.c>:103 in xpop_context Error occured in index.c:5371 - iw_open Couldn''t obtain write lock when opening IndexWriter -- Posted via http://www.ruby-forum.com/.
On 31.10.2006, at 18:02, John Mcgrath wrote:> Hi, I''m using Rails/AAF with Ferret 0.10.11, and my index occasionally > (every few weeks, roughly) becomes corrupted. > > If the index is busted, until I rebuild it our users are unable to > save > anything. I get errors like the one below, and the save rolls back.The acts_as_ferret plugin employs ActiveRecord callbacks such as after_update to index the models. If an exception is thrown inside a callback method, the action is rolled back.> My question is, is there any way to catch the error, and continue with > the save even if the model isn''t indexed?Several ways. You could overwrite the save mehtod (either on a per- model-basis or for ActiveRecord::Base) to read: def save begin create_or_update rescue => any_exception # deal with exceptions you can handle or re-raise end end Or, even better, you could patch the acts_as_ferret code to resort to a callback such as "rescue_error_in_ferret". See the ''ferret_create'' method of ''acts_as_ferret/lib/instance_methods.rb''. You''d basically wrap the method in a begin/rescue block and see if the model respond_to? :rescue_error_in_ferret. If it does, call that method or else re-raise the exception. Cheers, Andy
On Tue, Oct 31, 2006 at 07:47:30PM +0100, Andreas Korth wrote:> > On 31.10.2006, at 18:02, John Mcgrath wrote: > > > Hi, I''m using Rails/AAF with Ferret 0.10.11, and my index occasionally > > (every few weeks, roughly) becomes corrupted. > > > > If the index is busted, until I rebuild it our users are unable to > > save > > anything. I get errors like the one below, and the save rolls back. > > The acts_as_ferret plugin employs ActiveRecord callbacks such as > after_update to index the models. If an exception is thrown inside a > callback method, the action is rolled back. > > > My question is, is there any way to catch the error, and continue with > > the save even if the model isn''t indexed? > > Several ways. You could overwrite the save mehtod (either on a per- > model-basis or for ActiveRecord::Base) to read: > > def save > begin > create_or_update > rescue => any_exception > # deal with exceptions you can handle or re-raise > end > end > > Or, even better, you could patch the acts_as_ferret code to resort to > a callback such as "rescue_error_in_ferret". See the ''ferret_create'' > method of ''acts_as_ferret/lib/instance_methods.rb''. You''d basically > wrap the method in a begin/rescue block and see if the model > respond_to? :rescue_error_in_ferret. If it does, call that method or > else re-raise the exception.overwriting the callback handlers in your model would be another possibility: class MyModel < AR::Base acts_as_ferret ... # ferret_create is declared by aaf, and used for before_update and # before_create events. alias :old_ferret_create :ferret_create def ferret_create old_ferret_create rescue # handle the error... true # tell AR everything is fine end end Jens -- webit! Gesellschaft f?r neue Medien mbH www.webit.de Dipl.-Wirtschaftsingenieur Jens Kr?mer kraemer at webit.de Schnorrstra?e 76 Tel +49 351 46766 0 D-01069 Dresden Fax +49 351 46766 66