Resurrecting an old but helpful thread just to note for future Googlers 
that vanek's below solution works in a pinch (even if it might not be 
the most efficient)-- except "if e.to_s =~/away/" doesn't catch all 
possible exceptions that can raised by the db connection your forked 
process closed upon exit. Every so often a forked process will exit in 
the middle of an in-process db query in the parent, and you'll get a 
still-uncaught exception, "Lost connection to MySQL server during 
query". So you should at least do "if e.to_s =~ /has gone away/ or 
e.to_s =~ /Lost connection/" to catch that one as well.


vanek wrote:
> somebody posted their solution to this problem a few days ago.
> wouldn't hurt to give it a shot:
> 
>   def something
>     begin
>       fork do
>         emails.each { |email|
>           email.send  # calls SMTP
>           email.log      # calls ActiveRecord subclass
>         }
>       end
> 
>       arInstance.do_something # do a bunch of AR stuff
> 
>     rescue ActiveRecord::StatementInvalid => e
>       if e.to_s =~ /away/
>              ActiveRecord::Base.establish_connection and retry
>       else
>              raise e
>       end
>     end
>   end
-- 
Posted via http://www.ruby-forum.com/.

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to