Blog Post RSS ?

Blogs » Ruby on Rails » Timing out and retrying calls to third parties
 

Timing out and retrying calls to third parties

by Tim Lucas

When calling third parties you want to set them a sensible timeout, and you also might want to make a few attempts before giving up. Here’s a relatively succinct way to accomplish this in Ruby (3 attempts, each with a timeout of 5 seconds):


3.times do
  begin
    Timeout::timeout(5) do
      # Call your third party (for a example, a payment gateway)
    end
    @success = true
    break
  rescue Exception
    # Try again!
  end
end

if @success
  # Jump for joy!
end

I’m sure somebody will chime in with an even sexier way…

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Ping.fm
  • Twitthis

Related posts:

  1. Introducing the NEW SitePoint CSS, HTML & JavaScript Online References When we first released our popular HTML and CSS Reference...

This post has 3 responses so far

Sponsored Links

SitePoint Marketplace

Buy and sell Websites, templates, domain names, hosting, graphics and more.

Follow SitePoint on...