views:

35

answers:

3

We recently had an issue where a ColdFusion scheduled task didn't resume after a Windows upgrade and a CF server restart. Is there a way to monitor the health of scheduled tasks and be alerted if they are not running properly? Or would I need to write a task to parse the log files for that information?

+3  A: 

you can use the admin api to get information on your scheduled tasks. the following returns an array of structures with info about each scheduled task. you can then loop through the array and look at the last_run variable.

<cfset arySchedTasks = createobject("java","coldfusion.server.ServiceFactory").getCronService().listall() />
Daria
We used this method, and every task that ran logged itself to a database table. So we were able to reconcile the times it was SUPPOSED to run versus the times they ACTUALLY ran.
Ciaran Archer
Thanks. I wrote a quick CF script with this code to check the health of scheduled tasks. Right now it's running as a scheduled task itself, but I think I am going to port it over to a Windows task.
stomcavage
A: 

If you want to check that scheduled tasks are working at the most general level, one way is to schedule a "heartbeat" task, running as frequently as you wish. Set the task to update a counter, change a timestamp, send an email, trigger an "I'm alive" SMS every morning, add a log entry -- whatever makes sense. This won't tell you that all your tasks are running, but it will tell you that the server is alive, and the scheduled task system itself is working.

Another option is to funnel your tasks through a single point of entry -- a sort of front-controller for tasks. This delegates the setup and configuration of individual tasks to your code, rather than the CF Administrator. Your master task controller would include triggering code for each task. Schedule the controller to run at as frequently as needed -- so, one single task, rather than many. In the controller, something like this, perhaps every five minutes:

Check the time/date, compare against set of tasks
If time (or frequency) is A, run tasks P,Q,R, log success/failure
If time is B, run tasks S,T, log success/failure
If time is C, run tasks U,V,X, log success/failure    
Send heartbeat with success/failure codes for all relevant tasks

One advantage to this approach is that you can express much richer go/no-go workflows -- have tasks run at semi-randomized frequencies, run tasks based on the success or failure of other tasks, etc. If you see/receive the heartbeat indicator, you know your task controller did in fact run.

Ken Redler
A: 

Another simple option. Enable the output file for each task and check these files by independent Cron job: if file was changed within required time span should mean that scheduler task was executed.

Sergii