philnash / bitly

🗜 A Ruby wrapper for the bit.ly API
https://rubygems.org/gems/bitly
MIT License
451 stars 139 forks source link

timeout #23

Closed mpestritto closed 11 years ago

mpestritto commented 12 years ago

With the bitly snafu today, is there anyway to put in short timeout ( 2-3 seconds max ) or make it configurable for this library?

Some of my pages do on-the-fly Bitly link conversions for creating tweets and Bitly was taking over 30 seconds to return a timeout error which tied up processes on heroku. To a user, it seemed as the app was down because all processes were tied up.

philnash commented 12 years ago

That sounds like a good idea. Do you have time to knock up a patch at all?

burtlo commented 12 years ago

A temporary workaround that you could use is Ruby's timeout

require 'timeout'

Timeout.timeout(5) do
  sleep 10
  puts "I'm awake"
end

This will timeout raising the exception Timeout::Error: execution expired.

philnash commented 11 years ago

This has been merged to master and will be part of a new gem soon.