0

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.

rrk
  • 15,677
  • 4
  • 29
  • 45
  • Another option is to email the file 100% of the time. The programming is much simpler and it's a more consistent user experience. – Dan Bracuk Aug 03 '20 at 15:40
  • You could implement a JavaScript Ajax poll to determine when the file is available and then display a link to the file when it’s done. That’s how I would approach it. That way, you just render the page, which hits the backend asking for a download, get the ID of the job, and then make some JavaScript hit an Ajax endpoint that queries the job status given the ID. When complete, it returns the link. – Redtopia Aug 03 '20 at 17:15

0 Answers0