6 Replies Latest reply on Feb 3, 2009 6:53 AM by tclaremont

    sceduled task question

    craig_mac Level 1
      Hi i have a scheduled task that runs every 61 secs

      this task loops through a table added rows to a xml file then deleted each row.

      what i am worried about is this...

      if i had 10,000 records, the scheduled task starts to process, what happens if this process takes longer than 61 secs, will the next scheduled task start, or would it only run once the first task is complete?
        • 1. Re: sceduled task question
          Level 7
          craiglaw98 wrote:

          > if i had 10,000 records, the scheduled task starts to process, what happens if
          > this process takes longer than 61 secs, will the next scheduled task start, or
          > would it only run once the first task is complete?

          The former. As far as the web server and ColdFusion is concerned a
          scheduled task is simply a client requesting an URL little different
          then if a human requested the URL with a desk top browser. So you want
          to take all the care of making sure your schedule task code can handle
          multiple, overlapping requests. Just as if you where building it for
          human users who could make more then one request at the same time.

          • 2. Re: sceduled task question
            -==cfSearching==- Level 4
            > will the next scheduled task start, or would it only run once
            > the first task is complete?

            If you tell it to run every 60 seconds, my guess is it would do exactly that. You would need to add some logic to perform conditional processing. For example, if a particular file or status flag is present, then a previous task is still running, so exit without processing.

            But you could test it yourself. Create a test page, and force it to sleep for 60+ seconds. Then write something to a log file. Check the log file after a few minutes to verify the results.
            • 3. Re: sceduled task question
              craig_mac Level 1
              ok many thanks, how would i do a check to see if the scheduled task is already running though?
              • 4. Re: sceduled task question
                tclaremont Level 2
                Set up the scheduled task so that it creates a simple text file on completion of your intended process.

                Then, the very first step of your process is to check if the simple text file exists. If it does, immediately delete it and then run your process.

                The next time the scheduled task is called, its first step is to see if the text file exists. If it does NOT EXIST, then the previous process is still running.

                Perhaps there are more elegent solutions, but this is what I came up with in eleven seconds of pondering the question...
                • 5. Re: sceduled task question
                  Level 7
                  tclaremont wrote:
                  >
                  > Perhaps there are more elegent solutions, but this is what I came up with in
                  > eleven seconds of pondering the question...
                  >

                  Workable, but the same affect can be done with application scope
                  variables, without all the file writing.

                  <cfif NOT struckKeyExist(application,'thisScheduleTaskIsRunning') OR
                  application.thisScheduleTaskIsRunning is false>
                  <cfset applicaiton.thisScheduleTaskIsRunning = true>
                  ...
                  Do a bunch of stuff
                  ...
                  <cfset applicaiton.thisScheduleTaskIsrunning = false>
                  </cfif>
                  • 6. Re: sceduled task question
                    tclaremont Level 2
                    If having a record of the events is required, perhaps a better approach might be an entry into a log table. An indexnumber field, a datetime field and a single additional field with a value of "running" or "completed" might suffice.

                    At the start of the scheduled task, make an entry into the table that says "running". The last step of the task would be to change the value to "Completed".

                    If the most recent entry still says "running" then don't run the scheduled task the next time around.

                    If logging the activity is not required, then I agree that session variables is a better use of resources.