I thought I would write a little about this because anyone who knows me knows I am not a big fan of ColdFusion’s task manager. I think CF lacks hugely in this area, and although they have made some enormous moves forward with the task manager in 10, there are some key areas that they still lack in.

First major area, is logging and alerting. Before 10 when tasks failed, you would get a generic log entry in the admin logs and then nothing else would get done. So for those who depend on their tasks to run, it is kinda nice to know when it doesn’t. Even better, when the task fails it is nice to know where in the script the task failed so that if you are in a cfloop you know what iteration it was on when it failed. Trust me knowing the iteration of a failed task helps reduce time you spend tracking down errors in a task. Many times the problem is just in the data, not the script. So if you are trying to find why your task failed but have no detailed information, you may spend hours tracking down a task to find out that the data that it was looping over in a query was bad.

So I have always been a big fan of writing your own. Task manager. Now I know it sounds like a big job, and in part it is. But when it is done and you see the benefit, trust me it is worth the investment in time. Now the tedious part is getting all the moving parts together. Writing a task manager in CF is not hard, you just need to make sure it has all the bells and whistles you want.

All CF essentially does in the scheduled task manager is a http get on the URL you give the manager, at the interval you tell it to run that URL. That is the basics, so pretty easy right?. This is very easy to replicate in that all you need to do is build an app that stores its tasks in a database. Then write a script that queries those tasks and gets a list together of everything it needs to do an http get for. The script will loop through the query and call the url’s it needs to then exit. This means that all you need to do is setup 1 script that runs the http gets and put that script in the CF task manager.

I call my script ever 2 mins from the CF admin scheduled task area. So when CF runs the script it looks for all tasks that need to run within the next 2 mins. The next step I did was I wrote a custom tag that I use to wrap around my tasks that my CF script is doing a GET on. What this custom tag does is keep track of when it is called by your STM and weather it finished. What I also did was write a second custom tag that logs a custom message based on what you pass in. You can call this custom tag at any area you put it in your task. This allows you to see that if the task fails, you will know what step it was on when it failed.

Now putting together the script that runs all the tasks as I mentioned before can be a bit convoluted, especially If you are trying to replicate all the CF task manager offers plus more. One thing I added on was the ability to run tasks a a set number of days. This means if you want to run a task every 10 days you can. I had also added in grouping before CF 10 came out, because it fit into our business model but is not necessary.

Now the script that runs all the tasks is just that, a script. You will then need to write an app that gives the users the ability to administer tasks. Another benefit to all this, is that if you have a lot of web servers for different environments, like I do, this manager centralizes all your tasks and gives you the ability to customize your logging to fit your needs. I also run a task every morning that just goes out and checks how many tasks failed the previous day, and only sends an email to the appropriate people if there is a task that has failed.

I hope this post has shed a little light for you and reaches someone that can put this to use. Feel free to let me know if you have any specific questions on how this is all put together. Or specific script questions. I will be happy to help.