Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7166109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:21:38+00:00 2026-05-28T14:21:38+00:00

I have an application running on Heroku that, on occasion, reports Timeout::Error and (ActionView::Template::Error)

  • 0

I have an application running on Heroku that, on occasion, reports Timeout::Error and (ActionView::Template::Error) “execution expired”.

This happens all over the website (i.e. not in a specific controller) so I would like to create a function that will handle these two errors, first by retrying two times and the redirect the user to a page that will tell them that the server is busy.

My current plan is to use the following in ApplicationController:

  rescue_from Timeout::Error, :with => :rescue_from_timeout

  def rescue_from_timeout
    sleep 2
    retry 
  end

but this will just loop and loop. I want it to break after two attempts. How can I do that?

Also, How can I handle ActionView::Template::Error for “execution expired”? I don’t want to rescue all ActionView::Template::Error with retries, only the ones that provoke the “execution expired”.

This is what my exception says:

[Exception] home#index (ActionView::Template::Error) "execution expired"

or

[Exception] calculations#result (ActionView::Template::Error) "Timeout::Error: execution expired

My question, thus: How can I handle these two types of errors by first retry twice and then throw an exception / redirect to error page?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:21:39+00:00Added an answer on May 28, 2026 at 2:21 pm

    Define this method:

    def retryable(options = {})
      opts = { :tries => 1, :on => Exception }.merge(options)
    
      retry_exception, retries = opts[:on], opts[:tries]
    
      begin
        return yield
      rescue retry_exception
        if (retries -= 1) > 0
          sleep 2
          retry 
        else
          raise
        end
      end
    end
    

    And call with this:

    retryable(:tries => 10, :on => Timeout::Error) do
      your_code_here
    end
    

    You could put this in an around_filter in the application controller, that is the base class for all controllers in a rails application:

    class ApplicationController < ActionController::Base
    
      around_filter :retry_on_timeout
    
      def retry_on_timeout
        retryable(:tries =>  10, :on => Timeout::Error) do
          yield
        end
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application running under WebLogic that is using standard forms authentication. The
I have an application running on a Windows Server 2008, that is processing uploaded
I have an application running in Heroku. The app has a User model with
I have an application running in tomcat that has a bunch of configuration files
I have an application running only on Windows and a batch file that launches
I have an application running under apache that I want to keep in the
I have an application running that has entities that might be: CustomerType1, CustomerType2, and
I have application running for hours in embedded Linux, when suddenly the OOM Killer
I have an application running on Websphere Application Server 6.0 and it crashes nearly
We have an application running on a loadbalanced environment, let say webserver A and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.