I have never been a huge fan of ColdFusion's scheduled tasks. That's just an odd fear based on the fact that I have to rely on something outside of my applications. But, the fact is, scheduled tasks are essential if you want to do anything on a scheduled basis that is NOT triggered by user actions. I am also not a huge fan of creating / modifying / deleting scheduled tasks using the ColdFusion CFSchedule tag as it tends to leave phantom tasks running until the ColdFusion service gets restarted.
In order to deal with all of that emotionally, what I have started doing is creating a single point of entry for scheduled tasks in my ColdFusion applications. I have a single ColdFusion template that launches all of my application's scheduled tasks:
<!--- Kill extra output. ---> <cfsilent> <!--- Send girlfriend random text message so that she knows that I am thinking about her. ---> <cfhttp url="./tasks/send_random_text_message.cfm" method="GET" timeout="1" throwonerror="false" /> <!--- Clean up temp files. ---> <cfhttp url="./tasks/purge_temp_files.cfm" method="GET" timeout="1" throwonerror="false" /> <!--- Send out scheduled emails. ---> <cfhttp url="./tasks/scheduled_emails.cfm" method="GET" timeout="1" throwonerror="false" /> </cfsilent> <!--- We are done running tasks. ---> Done.
As you can see, this single point of entry turns around and launches additional scheduled tasks using CFHttp calls. Each CFHttp call is given one second to execute before it times out (without error) and the current page moves onto the next task.
The down side to this is that each task has to know a bit more information. Tasks cannot assume they are only run once every N hours or days. Since this one point of entry is responsible for every scheduled task on the site, it must run as often as the smallest required time interval. This means that a task designed to run once a day might end up getting called once every 15 minutes. That task has to know to ONLY run once per day even though it is "asked" to run much more often.
The up side to this, however, is that you only need to set up one scheduled task in the ColdFusion administrator (per application). If you have any additional scheduled task requirements all you have to do is update your point of entry. You never need to go back to the ColdFusion administrator for task set up for the application (unless, of course, you need to increase / decrease the interval at which the task runs).
So far, I have used this with great success. And, I find that it forces me to write much better, smarter scheduled tasks that don't rely on the scheduled task interval.
Want to use code from this post? Check out the license.