Monday, May 19, 2008

Application Scheduling

Sometimes it is necessary to perform activities on regular intervals such as:
  1. Sending daily email alert.
  2. Compiling wip @ a specific time.
  3. Compiling yield or transactions either shiftly or daily.
This can be easily done by writing a console (non GUI) application and then scheduling the application to run at regular intervals. With Windows 2000, Windows XP, and Windows 2003, you can use the Windows scheduler.

The Windows scheduler was first introduced in Windows NT but it did not provide a nice interface for adding to and viewing the schedule (using AT command - similar to the command available in Unix). This has since been improved.

Nice thing about the Windows Scheduler is you can set it to run as different users. Typically, most will run under Admin account. However, note that when it runs, the screen will only display in the console.

One of the benefit, Windows Scheduler has over the Unix (cronjob) is that it has a built-in mechanism that will ensure only a copy of the schedule item will run at any time. While Unix does not do that. For example, you may schedule extractData and schedule it to run every 3 minutes. In Unix, if the extract takes more than 3 minutes, you may end up with multiple copies running at the same time. This will not happen if scheduled in Window scheduler.

There are also some failsafe such as automatically abort if the job takes more than a specified amount of time.

Finally when we schedule a job we typically expect it to run automatically. There are some additional precaution we should take:
  • have a log file output so that we can trace when there are problems. Easiest way is to redirect the output of the program (for example extractData >> c:\log\extractData.log)
  • Have the application generate a heartbeat file each time it completes successfully and then have another program monitor the heartbeat file modified time. If the heartbeat update time exceeds a threshold, just have the application send an alert.

No comments: