2 Replies Latest reply on Feb 28, 2007 11:08 AM by bigbrain28

    Control Execution order on one page?

    bigbrain28 Level 1
      I have been using cflock erroneously thinking it was for this purpose. Here is my issue; I have an action page that accepts a JPG from a file upload field of a form then runs the image through a ImageMagik custom tag twice (once to resize for display and once to resize/create a thumbnail) THEN the page is meant to upload the 2 images to our remote/backup server.
      I have inserted a cfloop that counts to 6000 as a time buffer (see code)
      My issue is that the CFFTP starts to send the uploaded file prior to the ImageMagik tag even starting its routine on the image, then is interrupted mid stream. The result is one server has a perfect pair of images, and the other gets a perfect thumb, and a truncated full-size original. This is inconsistant, but annoying.

      Is there not a cflock type command to enclose commands on a page so thet will only progress down the template once the previous function has completed? I'm thinking old school "while" type command, but I don't know where to start. Also the file is renamed on upload (to avoid conflicts) so checking if file exists would not yield truth about resize being complete.
        • 1. Re: Control Execution order on one page?
          Level 7
          CF is processed, sequentially, from top to bottom of the template. Each
          preceeding instruction must complete before the next one is processed.

          The only way you could see what you're seeing is if this magicktag.cfm file
          spawns some non-CF process to do the image processing, and that process
          runs asynchronously with CF. It's probably worth checking the docs of it
          to see if this is the case, and - if so - whether it ever returns anything
          or sets anything detectable to CF that it's finished. And then get CF to
          wait for THAT, rather than looping to some random number (which will eat
          your CPU whilst it runs, and - if anything - will make your problem WORSE).

          If there's not "completion flag", you should probably wait until the file
          you're trying to FTP actually exists before trying to FTP it.

          If you need to wait an arbitrary period of time, use the sleep() method of
          java.lang.Thread, which is more accurate and far less CPU intensive than
          just making CF loop for n iterations, in the hope that on the machine
          you're running it on, n iterations equates takes longer ot execute than the
          process you're waiting for (which will be slowed up by the loop...).

          --
          Adam
          • 2. Control Execution order on one page?
            bigbrain28 Level 1
            Thanks for your reply, it certainly makes sense. I have modified the code to include a cfdirectory list to check that the file exists, and also have added a "hold" folder for the first upload to go to. Then the cf_magik will grab from there, resize and put the new & thumb in their respective folders - This way an unresized image cannot be FTP'd because the checker will not find the original in that folder. I am still using a cfloop, but only as a means to cycle trhu checking the dir for the file: