• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 899
  • Last Modified:

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

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
jbrahy
Asked:
jbrahy
  • 7
  • 4
  • 3
  • +1
1 Solution
 
danrosenthalCommented:
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
 
jbrahyAuthor Commented:
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
 
danrosenthalCommented:
You can redirect the user to a "waiting" page and will know when it is done when the file is there.
0
[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

 
jbrahyAuthor Commented:
the problem is that the file is there while it is adding files. it's just increasing in size.
0
 
danrosenthalCommented:
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
 
jbrahyAuthor Commented:
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
 
danrosenthalCommented:
CFTRY/CFCATCH will catch errors.
0
 
jbrahyAuthor Commented:
ok, I'll try it and let you know how it goes, thanks
0
 
dgrafxCommented:
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
 
DAJEDCommented:
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
 
jbrahyAuthor Commented:
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
 
dgrafxCommented:
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
 
jbrahyAuthor Commented:
ok, I'll try that and let you know
0
 
jbrahyAuthor Commented:
Thank you all for your time!
0
 
dgrafxCommented:
you're welcome and good luck
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 7
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now