How to control timeout exceptions.

J

Junaid Junaidi

This is code that i am using for fetching updates from twitter. I used
SystemTimer gem from
thoughtwork(http://ph7spot.com/articles/system_timer) to ensure that we
don't get anymore timeout exception and crashed page.As article
(http://ph7spot.com/articles/system_timer) points out weaknesses of
timeout.rb implemented in ruby 1.8. We are using ruby 1.8 in production.
After system_timer we also handle "rescue Twitter::Error" but they also
didn't work. I know we can also option to configure timeout in the http
client library but i think these both should work fine.

We are using rails 2.2.2 and ruby 1.8.6. Here is my code.

TWITTER_SERVICE_TIMEOUT = 25s

begin
SystemTimer.timeout(TWITTER_SERVICE_TIMEOUT) do
c = Twitter::Client.new:)login =>
profile_twitter.email,:password => profile_twitter.password)
my_timeline = c.timeline_for:)me, :since => 30.minutes.ago)
end
rescue Twitter::RESTError => re

rescue Timeout::Error
#my_timeline = nil
end

Exception i got mostly

/usr/lib/ruby/1.8/net/http.rb:560:in `initialize'
/usr/lib/ruby/1.8/net/http.rb:560:in `open'
/usr/lib/ruby/1.8/net/http.rb:560:in `connect'
/usr/lib/ruby/1.8/timeout.rb:53:in `timeout'
/usr/lib/ruby/1.8/timeout.rb:93:in `timeout'
/usr/lib/ruby/1.8/net/http.rb:560:in `connect'
/usr/lib/ruby/1.8/net/http.rb:553:in `do_start'
/usr/lib/ruby/1.8/net/http.rb:542:in `start'
/usr/lib/ruby/gems/1.8/gems/twitter4r-0.3.0/lib/twitter/client/base.rb:9:in
`http_connect'
/usr/lib/ruby/gems/1.8/gems/twitter4r-0.3.0/lib/twitter/client/timeline.rb:66:in
`timeline_for'
 
R

Robert Dober

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,961
Messages
2,570,131
Members
46,689
Latest member
liammiller

Latest Threads

Top