Skip to main content
January 30, 2009
Question

sceduled task question

  • January 30, 2009
  • 5 replies
  • 619 views
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?
This topic has been closed for replies.

5 replies

tclaremont
Inspiring
February 3, 2009
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.
Inspiring
February 2, 2009
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>
tclaremont
Inspiring
February 2, 2009
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...
Inspiring
January 30, 2009
> 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.
February 1, 2009
ok many thanks, how would i do a check to see if the scheduled task is already running though?
Inspiring
January 30, 2009
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.