How to change default request time out on Heroku?

前端 未结 3 770
日久生厌
日久生厌 2021-01-07 23:24

My app is built on Rails and my production server is on Heroku.

My application is mostly used for file upload and file processing and it takes more than 50 seconds f

相关标签:
3条回答
  • 2021-01-07 23:34

    As already mentioned, you need to process it in the background because you cannot change the timeout enforced by Heroku. This is actually a good thing, because it will allow for a much better design where the web application is responsive and it can also scale much better.

    What this means is that you need to use something like for instance delayed job and you can read about it on Heroku here.

    The flow of things would be something like this:

    1. upload the document within the hard limit (timeout) enforced by Heroku.
    2. schedule a background job to process document and return 200 OK to the browser.
    3. browser waits for completion by e.g. background AJAX polling of a flag to see when background job is ready.
    4. delayed job picks up scheduled work and upon completion it sets the flag to indicate the background job is done.
    5. Browser can now inform the user that it is done (up to your application to know what fits).

    This is an idea how this can be done. You have a few different ways you can do it and delayed job is just one you can choose from.

    0 讨论(0)
  • 2021-01-07 23:40

    This is not possible according to Heroku's documentation

    The timeout value is not configurable. If your server requires longer than 30 seconds to complete a given request, we recommend moving that work to a background task or worker to periodically ping your server to see if the processing request has been finished. This pattern frees your web processes up to do more work, and decreases overall application response times.

    0 讨论(0)
  • 2021-01-07 23:49

    You should upload your large files directly to Amazon S3 or similar and then process the file using a Heroku background worker. Typically, your web page will use some sort of polling (usually an AJAX request) to see when the processing has finished and update the front end.

    0 讨论(0)
提交回复
热议问题