views:

471

answers:

5

Why not use the Windows scheduler? I have several applications that have to run at certain times according to business rules not the typical every weekday at 1pm.

I also need a way for the applications to provide feedback of their progress so that I can have rules that notify me when the applications are running slow or aren't even running anymore.

What Windows API should I be looking into? (like, a time version of the FileWatcher apis)

What's the best way to have the application notify the scheduler of its progress (files, sockets, windows messages, ???)?

A: 

Use service with a timer that is fired regulary (for example each minute). It reads the schedule and looks if some are due before the next iteration. If so, you can execute them.

You can add an interface that shows all running apps. For the feedback and query that using a desktop application.

Gamecat
+1  A: 

AppControls has a CronJob component that you can use to create scheduled events. This saves your program from having to wake up every minute and check the schedule itself. Instead, just schedule the job and indicate a callback method.

I have used this component for scheduling jobs myself and have been very happy with the way that it works.

Scott W
+1  A: 

For Vista/Win2k8, there's the nice Task Scheduler 2.0 API: http://msdn.microsoft.com/en-us/library/aa384138(VS.85).aspx. Previous version have the Task Scheduler 1.0 API, but I've never used it.

codekaizen
I took a little time to look at this already; and if I just wanted to run something at a certain time, bizzaro rules and all, this would probably be the way to I'd go. Wanting the extra feedback is pulling me away from this.
CrashCodes
For the notification, you might consider using a the WMI provider / subscriber model. It sounds like the data you want to collect is along the lines of monitoring, so this would be an ideal mechanism.
codekaizen
+1  A: 

I think what you really want is a common framework for your applications that report to something (you or the system messages or tracing or perfmon, event log, whatever) and also to receive via some inter process protocol a way to receive messages and respond.

based on the reporting you can change the scheduling or make changes, etc.

So, there is some monitor app, and then each of your other apps does common reporting.

events I can think of: - started - stopped - error - normal log messages - and of course specific things your apps do.

I think there are probably existing classes/framework that do this - you'll have to check around.

If it were me, I would make a service that could talk to all the other apps and perhaps was even an http server. It would be able to route messages to particular apps and start stop those processes and query them.

There are lots of ways to do what you want though. those were just off the top of my head.

Alternatively you might just be able to get these to be services and they handle messages sent to them. Their normal processing does nothing until they are "woken up" with some task command.

Tim
+1  A: 

You have more questions in one. Normally you should split them. But let's overlook this and try to answer.

  1. To schedule certain events (including running an application): Use TJvScheduledEvents from JVCL. IMHO JVCL is the best Delphi open source library around with extensive number of components, developers & support. TJvScheduledEvents is quite neat, uses threads for event scheduling and also you have in JVCL a detailed editor for your events (it needs a small hack to use it though).

  2. To provide 'feedback' from your applications to a (remote) central point: A very very very good solution (if your requirements permit) is to log the progress of your applications in a table (let's call it LOG) on a Firebird server. In LOG you can have the following fields: COMPUTER, USERNAME, APPNAME, MSG, LOGDATE (etc. etc.). In the After Insert trigger of the LOG table you can fire an event (let's call it NEW_LOG). In your console app you can register the interest for this event and so, your application will be automatically updated with everything which happens in any of your applications, so you can do log analysis, graphs etc. Of course you can do it with IB, but IB costs.

...going on Windows API route you need headers (which probably aren't translated), you'll encounter our dearest Pointers/PChars etc. etc. Of course, building from scratch everything isn't worthwhile but when this is already done in a Delphi way, why don't use it?