• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Looking for ideas....

Explorer ,
Mar 28, 2020 Mar 28, 2020

Copy link to clipboard

Copied

Hello,

 

Just wondering how people would handle the following problem. So we have export functionality which is called via a JavaScript post. Now this export could take a couple of minutes to generate so I'd like to explain that to the user and let them carry on to other pages and eventually notify them when their download is ready. My immediate thoughts were to have a scheduled task running which would be checking a table every couple of minutes to see if there was any exports generated in the previous 2 minutes for the logged in user and if so could Let them know. Problem is I don't want a scheduled task running away when there may be no exports to be downloaded. It just seems like unnecessary processing. 

Anyone any ideas on how to accomplish this in the easiest and most elegant manner. 

Thanks

TOPICS
Advanced techniques , Asynchronous , Event gateways

Views

1.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 29, 2020 Mar 29, 2020

Copy link to clipboard

Copied

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.

 

OK, that said, this is a perfect job for CFTHREAD and some sort of tracking variables, like the Session scope. You could use CFTHREAD to launch the task, then have it write to a Session variable when done, then the next page request from that user could see the Session variable and respond accordingly. The JavaScript XmlHttpRequest could invoke this page without navigating the user to it directly, of course. This is simpler than a scheduled task, and should be less overhead. Of course, if you're not using Session variables, then you could have the CFTHREAD task write to a database table and have a check of that table on subsequent page requests. But this is a perfect job for Session variables if you can use them.

 

Dave Watts, Eidolon LLC

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 29, 2020 Mar 29, 2020

Copy link to clipboard

Copied

Hi Dave,

 

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. 

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 03, 2020 May 03, 2020

Copy link to clipboard

Copied

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> 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 11, 2020 May 11, 2020

Copy link to clipboard

Copied

Hi,

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?

 

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 11, 2020 May 11, 2020

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 04, 2020 May 04, 2020

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 11, 2020 May 11, 2020

Copy link to clipboard

Copied

Hi,

 

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. 

 

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation