I have a ROR app on heroku.There are 8 optional text fields on the app, user can fill it or let it be empty according to their requirements.
The more text fields user fill, the more processes my app needs to do. My app will process the request more than 30s if there are more than 5 fields be filled and it will cause Heroku timeout.
Is there any solution to deal with this problem?
I heard that using javascript and ajax can divide a request into two parts, I think it will avoid the timeout problem. However, I am not sure how to do it.
Thanks!
You just need to do the processing as a background job. On Heroku it’s super easy. Use Resque + Redis, but you can also use DelayedJob. Resque (built by github) is a queueing layer on top of Redis (a key value store). It’s much easier to scale than doing queuing with DelayedJob, but either way works.
Once that’s setup, here’s all you need to do:
If your form is a user creation form, the code might be like this:
… you could also write it like the following (storing only the
idin the queue, not the params)By queuing up everything, the user will be almost immediately taken to the next page.
If the user needs to see the result of the processing immediately on the next page, however, you’re just going to have to figure something else out.