We have a web application in which the user enters the input to some computational problem, sends it to a server, and the server calculates and returns the result. For some inputs, the calculation takes a long time, so the server returns a page saying “I am working on it”, and continues working on it in a background thread. When the solution is ready, the thread sends an email to the user.
This worked well on a Linux server, but when we moved it to Heroku, it stopped working – we found out that, when the server returns a reply to the user, Heroku stops all threads, including the computation thread.
What is the correct way to implement this scheme in Heroku?