Anyone any ideas on how to accomplish this in the easiest and most elegant manner.
I hear the word "elegance" a lot when people talk about code, and I'm not really entirely sure what it means. I mean, I know what people think they mean, but I'm not sure it lines up with what they really mean. And I've heard a lot of weird advice given in the name of elegance, when said advice might degrade performance or functionality. So, my first piece of advice is not to worry too much about elegance.
Dave Watts, Eidolon LLC
Thanks for that. I would say elegant may have been a wrong choice of words in this case and did cross my mind as I was hitting the post button.
We do use session variables but sparingly. I did expermiment with cfthread and it did do what I wanted but I recall we had some issues with cfthread previously which required us to remove it. For this reason I parked it for time being. I think il revisit it now though and look at adding a couple of new session variables.
I am also thinking along the lines of scheduled tasks - in combination with a session check. The pseudocode follows:
1) On ColdFusion page where export functionality is triggered: <!--- Verify in the database whether the export has been generated. ---> <cfif resultOfVerification is true> <!--- Notify user that download ready, then abort. ---> </cfif> <cfset session.isExportHavingUniqueIDGenerated = false> <cfif not session.isExportHavingUniqueIDGenerated > <cfschedule action = "update" task = "checkExport" operation = "HTTPRequest" url = "http://127.0.0.1:8500/exports/checkExport.cfm" startDate = "3/20/2020" startTime = "9:00 AM" interval = "120"><!--- Task scheduled every 2 minutes ---> </cfif> 2) In the page checkExport.cfm <!--- Verify in the database whether the export has been generated. ---> <cfif resultOfVerification is true> <cfset session.isExportHavingUniqueIDGenerated = true> <cfschedule action = "delete" task = "checkExport"> </cfif>
Thanks for that. My previous experience of scheduled tasks was running them very frequently or else once a day or week. I'd never considered the idea of creating them on the fly then deleting when finished. If there was a lot of activity on the system and tasks were being created and deleted quite often would there be much of a performance hit would you think?
On the contrary, scheduled-tasks are designed to optimize the performance of your application. You allocate a number of threads for them (the default is 10 - off the top of my head), and a task runs only when an allocated thread is available.
We have similar functionality is a system I support. We spin of the export as a separate request to run in the background then user has the option of waiting at a status screen that monitors the export and reports percent complete or they can opt to be notified via email when the export is done. The email is sent by the export process when complete so no constant pinging of the system.
Could easily send email on completion of the process I just think its more cumbersome for them to have to check their email to acknowledge that the file has created. Thats why i'd prefer something more immediate and on the system they are using.