I have a Coldfusion app and page where I generate and download a file. There are cases when that process takes a lot of time. I would like to implement it so that the whole process looks like this:
- start the process of generating and downloading a file
- if the file is generated within a certain time (e.g. 10 sec.), then provide it to the user immediately
- if not, then after the expiration of the allowable time for generation, display a message that the file will be sent to the user email.
I think the CF threads can help me, but I haven't used it earlier.
thread action="run" name="generateFile" {
var createFileResult = myService.createFile();
}
thread action="join" name="generateFile" timeout="10000"; // 10 sec.
if (generateFile.status != "COMPLETED") {
thread action="terminate" name="generateFile";
var createFileResult = new CreateFileResult(message="We will produce the file and send you a link to download.");
}
Currently, I show a message if the file has not generated, but at the same time, I lose the ability to generate the file on the first request. I'm interested in the following: how without killing the thread in which the file is generated (if it is possible), complete the file generation in the background for a user and immediately to send it to a user email?
I want to implement it in this way because I want to use the server resources rationally and not ignore the result of the work done if the file wasn't generated at the first user request and don't load the server again when the same file is generated for sending to email.