Question

I have a script that will run everyday once depending upon the scheduler setting in Coldfusion admin.

So is there any way we can know that the scheduler already executed, So that if any one will run that file again manually it will not execute the task again?

Was it helpful?

Solution

As Matt and Dan mentioned, I would recommend a flag indicating when you started and completed the task so that you can reference that to prevent it from running twice simultaneously (if that is your goal) or within a certain time frame.

Personally, I prefer to track this in a database as that provides for good flexibility, but you could use log files as well (via, cflog for example) and that would work as well.

You might also set the flag in an Application-scoped variable. This variable would vanish on a server restart, which might be a plus or a minus depending on your particulars.

I actually wrote a CFC a while back that I use regularly for this sort of thing. I have one .cfm page that is called by cfschedule call this component which manages all of the scheduled tasks. The component tracks (via database) when everything runs to make sure it has no conflicts. It also keeps track of success, failure, execution times. One thing that is really handy about that is that I can view reports of execution times over time and see if some of my scheduled tasks are starting to run long (so I can address it before it becomes a major issue).

Part of com.sebtools, if you are interested.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top