This content has been marked as final. Show 6 replies
> 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.
> 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.
ok many thanks, how would i do a check to see if the scheduled task is already running though?
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...
> 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>
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.