Solved

How do I wait for a cfexecute tag to finish before continuing?

Posted on 2006-11-02
15
869 Views
Last Modified: 2013-12-24
I have a site that allows people to add files to their basket and when they are done I zip it up and let them download the zip file. I have found out that when the zip file is 400mb or so and they are trying to download it the zip file is often corrupted. It turns out that the cfexecute tag is allowing the following code to execute before it's completed. Is there a way to wait for the process to finish before I continue on to the next code?

I've tried putting it into a java program but I kept getting null pointer exceptions and I'm very aggravated with it. I need a solution asap, please help!


0
Comment
Question by:jbrahy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 3
  • +1
15 Comments
 
LVL 15

Expert Comment

by:danrosenthal
ID: 17862408
Can you rename it once it is done creating the zip. This way the file will only be there when it is ready to be downloaded. You can easily check for the file using FILEEXISTS.
0
 
LVL 1

Author Comment

by:jbrahy
ID: 17862555
that would be great if I knew when it was done creating the zip. but that's the problem that I'm having is that I don't know when it's done. do you have any ideas of how to know when it's done? is there a way to list windows processes so I can grep for the particular one that I launched. I guess I would also need the process id for it from cfexecute.
0
 
LVL 15

Expert Comment

by:danrosenthal
ID: 17862723
You can redirect the user to a "waiting" page and will know when it is done when the file is there.
0
Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

 
LVL 1

Author Comment

by:jbrahy
ID: 17862767
the problem is that the file is there while it is adding files. it's just increasing in size.
0
 
LVL 15

Expert Comment

by:danrosenthal
ID: 17862772
Exactly! That is why I suggested renaming it as soon as it is done. The temporary loading file is not what you will be checking for. You will check for the final filename which will only be there in complete form.
0
 
LVL 1

Author Comment

by:jbrahy
ID: 17862809
I understand what you mean by renaming the file, but when I pass the filename and the name of the zip file to 7zip to create the zip file, it doesn't give me the opportunity to rename it after it is done creating the zip file. I would have to run another process to rename the file but that would have to be done after the program is finished creating the zip file. And that's my problem, I don't know when the zip file is done being created.

I could try to rename it in a loop but it won't let me move it until it is done. Is there a way to ignore errors and keep looping?

0
 
LVL 15

Expert Comment

by:danrosenthal
ID: 17863138
CFTRY/CFCATCH will catch errors.
0
 
LVL 1

Author Comment

by:jbrahy
ID: 17863206
ok, I'll try it and let you know how it goes, thanks
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 17865799
why not do this:
when they are finished adding files and they click "Done"
1) call your zip cfc which starts zipping
2) at the end of the zip code use cfheader & cfcontent like:
<cfheader name="content-disposition" value="inline; filename=#whatevername#.zip">                              
<cfcontent type="application/unknown" file="#ZipPath##whatevername#.zip" deletefile="no">
where zipPath is absolute path "D:\websites\zipfiles\"
When the zip is finished zipping - cfcontent will push the file out to the user in the form of a file download dialog
It won't try to do this until the zip is finished zipping.

I just read your original post - I guess I assumed you were using one of the zip cfc's available.
Or is that the java program you're having trouble with that you mentioned.
That's really how you should be doing it - once you get it to work of course.            
0
 
LVL 1

Expert Comment

by:DAJED
ID: 17865871
That is good,

ASSUMING THAT YOU ARE USING CFMX7

Alternatively, you can create a thread and wait for a specified period of time.  After the wait, then you will check for the datelastmodified.  If it is greater than a specified time (you decide) then you can say that the file is finished.

Consider this.
<cfset thread = CreateObject("java", "java.lang.Thread")>
<cfset DM = 0>
<cfset TimeLimit = 30> <!--- File has to NOT be modified for that length of time --->
<cfset SDte = Now()>
<cfset CDte = Now()>
<cfloop condition="#DM# LT #TimeLimit#">
    <cfset thread.sleep(4000)> <!--- wait for 4 seconds --->
     <!---
             1.  Read the file
             2.  Get the file's date last modified  
             3.  Check the value of Sdte
                   a) if SDte is zero then give SDte the value of the file's date last modified
                   b) if SDte is NOT zero give CDte the value of the file's date last modified
             4. Give DM the value of the time difference (in seconds) of SDte and CDte
     --->
</cfloop>
you can assume that the file IS finished because:

You are only going to START the creation the script once the client is finished adding his/her files.

Hope I helped
0
 
LVL 1

Author Comment

by:jbrahy
ID: 17870792
This is what I've been trying but it's moving the partial file and not erroring out when the file is still being written to. I'm going to try to get the date modified like DAJED suggested and hopefully that will work.

thanks

 
<CFEXECUTE
      OUTPUTFILE="d:\sites\www.thissite.com\www\downloads\output.txt"
      TIMEOUT="90"
      NAME="C:\Program Files\7-Zip\7z.exe"
      ARGUMENTS="a -tzip #tempZipPath# #filenames# ">
</CFEXECUTE>

<CFLOOP from="1" to="59" index="index">
      <CFSET thread = CreateObject("java","java.lang.Thread")>
      <CFSET thread.sleep(1000)>
      <CFTRY>
            <CFFILE ACTION="MOVE" source="#tempZipPath#" destination="#zipPath#">
            <CFIF FileExists(zipPath)>
                  file exists
                  <CFFLUSH>                  
                  <CFCONTENT type="application/x-zip">
                  <CFLOCATION url="#zipURL#">
            <CFELSE>
                  doesn't exist
                  <CFOUTPUT>#zipPath#</CFOUTPUT>.
                  <CFFLUSH>                  
            </CFIF>            
            <CFCATCH>
                  <CFOUTPUT>#index#</CFOUTPUT>.
                  <CFFLUSH>                  
                  </CFCATCH>
      </CFTRY>
</CFLOOP>


0
 
LVL 25

Accepted Solution

by:
dgrafx earned 500 total points
ID: 17870855
ok look - you're looking at it wrong.
get rid of the cfexecute
get rid of the loop and the cflocation and the cffile move (you don't need to move anything I don't believe - just zip files from where they to a zip at any location you choose - the zip cfc should show you how to supply the path)
actually, scratch everything above and use one of the zip cfc's like the one I posted in other thread.
It should give you instructions on how to throw your list of files at it and it will zip them.
Do just that first to make sure all is swell

Then use the cfheader and cfcontent as I posted above.

It works perfect.
This isn't just something I threw together to answer your question.

Now that I see your code - the problem is how you're doing it.
0
 
LVL 1

Author Comment

by:jbrahy
ID: 17870884
ok, I'll try that and let you know
0
 
LVL 1

Author Comment

by:jbrahy
ID: 17870945
Thank you all for your time!
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 17870956
you're welcome and good luck
0

Featured Post

Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question