stomcavage
stomcavage

Reputation: 1059

Check health of scheduled tasks?

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?

Upvotes: 2

Views: 2545

Answers (4)

Brandon Wood
Brandon Wood

Reputation: 1

The suggestion that the user gave for finding out what processes are running is brilliant.

<cfset arySchedTasks = createobject("java","coldfusion.server.ServiceFactory").getCronService().listall() />

Using this, I found that when I moved the scheduled tasks from one server to another by copying the neo-cron.xml from one server to another many of the processes stopped processing. When I reviewed the processes using the scheduled task list, I noticed that the processes that WERE working didn't have encrypted passwords in the password field while the ones that DID NOT work had encrypted passwords that prevented the processes from running due to the fact that when the processes ran, it couldn't decrypt the passwords that were in the neo-cron.xml file (as they were from a different server and therefore the decryption didn't work). To solve this issue, I opened up the neo-cron.xml file and manually took out all of the passwords in the password section of each profile and then saved it and replaced the file with the passwords in it and then restarted the CF service. Once restarted, the processes started running again by themselves.

I wanted to share this in case anyone else was having the same issue. If your tasks are kicking off after moving servers, check to make sure there aren't any passwords store in the neo-cron.xml file.

It took my ages to figure this out, so hopefully this helps someone else.

Upvotes: 0

Sergey Galashyn
Sergey Galashyn

Reputation: 6956

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.

Upvotes: 0

Ken Redler
Ken Redler

Reputation: 23943

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.

Upvotes: 0

Daria
Daria

Reputation: 326

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() />

Upvotes: 5

Related Questions