Stuart Wade
2006-Jul-20 19:45 UTC
[Rails] guru needed: connecting to a second (remote) db that may not be available
hi, My rails app connects to 2 databases a local one and a remote one. No problems there.. The problem is that the remote database may or may not be available at any given time. My problem: when the remote db is unavailable, any time my code tries to query the remote database it hangs for a few minutes until it times-out. I would very much like to change the timeout value to something lower so my rails app can continue to operate at least semi-normally while the remote db is unavailable. i tried using verification_timeout, not sure if i did something wrong but it didn''t work.. tried Mysql::OPT_CONNECT_TIMEOUT (or something like that) and that didn''t seem to do much either, again not sure if i used it right (both have slim to none documentation).. lastly i tried wrapping different stuff in a Timeout::timeout block (establish_connection, connect code in connection_adapter code, etc etc) NO DICE.. can anybody help me with this issue? thanks stuart
Travis Michel
2006-Jul-20 21:30 UTC
[Rails] guru needed: connecting to a second (remote) db that may not be available
Hi, I''m not a guru, though I have a suggestion. Fall out of rails and back to system commands, ping the database and if there is no responce then raise an exception to get out of the remote query block. Example: raise (DangitException, ''not again'') if /Destination Host Unreachable/m =~ `ping -w 2 x.x.x.x` its quick but not the best. cheers, - trav On 7/20/06, Stuart Wade <teflon_of_armada@hotmail.com> wrote:> > hi, > > My rails app connects to 2 databases a local one and a remote one. No > problems there.. The problem is that the remote database may or may not > be > available at any given time. My problem: when the remote db is > unavailable, > any time my code tries to query the remote database it hangs for a few > minutes until it times-out. I would very much like to change the timeout > value to something lower so my rails app can continue to operate at least > semi-normally while the remote db is unavailable. > > i tried using verification_timeout, not sure if i did something wrong but > it > didn''t work.. tried Mysql::OPT_CONNECT_TIMEOUT (or something like that) > and > that didn''t seem to do much either, again not sure if i used it right > (both > have slim to none documentation).. lastly i tried wrapping different stuff > in a Timeout::timeout block (establish_connection, connect code in > connection_adapter code, etc etc) NO DICE.. > > can anybody help me with this issue? > > thanks > > stuart > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- p [151,40,154,157,166,145,40,162,165,142,171].collect { |ii| eval ''"\\''+ii.to_s+''"'' }.join -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060720/d2d57a3c/attachment-0001.html