views:

282

answers:

3

I have a database job that runs occasionally at night and I need a windows service to poll the database regularly to do some more work after the SQL job is done. I am a looking for a solid example to write a scheduler that can fail gracefully without crashing the service.

A: 

Just make it a scheduled task. See http://stackoverflow.com/questions/390307/windows-service-vs-scheduled-task

Mark Ransom
that wouldnt work since he wants it to run only after a SQL job is done
Chad Grant
He said "pool the database" which I assume is a misspelling of "poll", so my answer stands.
Mark Ransom
yes I meant poll sorry but I would rather have a windows service since it's easier to monitor, log events ...
Hatim
So... what you're saying is he should be polling his "Under Heavy Load" SQL Server to see if it's done. Them have the nagging polling app kick off the scheduled task ... Seems fine until you think about the amount of code and ways the polling app could fail like starting a kob on another machine. MSMQ was designed for this case. Seems to me you guys are trying to get it to work with some bubble gum and string.
Chad Grant
The database is not under heavy load so polling it wouldn't hurt specially the polling would happen each hour so going with the simplest solution without having to add an MSMQ CLR procedure and then monitor it is viable for us. Thanks for all the help guys!!
Hatim
@Deviant - I didn't say polling was the best way, I just said scheduled tasks were a good way to poll. You make a good point.
Mark Ransom
+1  A: 

I would use MSMQ, add a final step to the job that adds a message to the queue (Via ActiveX Script / COM or a .net call if you can)

Then have your service monitoring the Queue.

As far as not crashing the service, that would all be up to you and error handling etc...

Chad Grant
I would rather not add another dependency to the solution it's already a pretty large 1MM+ lines of code with multiple third party libraries...
Hatim
well if you want to ghetto rig it, just add a cmdexe Step at the end that starts your job from the command line via start the service with sc http://technet.microsoft.com/en-us/library/bb490995.aspx then shut the service down when it's done and wait for tommorrow
Chad Grant
So you are interested in some CodePlex project, but not MSMQ?? For some reason, a lot of people are intimidated by MSMQ . . . you'd be suprised how simple/easy it is to implement.
MattH
A: 

Take a look at http://codeplex.com/TaskService

Khurram Aziz
This looks promising and it's along the lines of what I was looking for. Thanks Khurram
Hatim
LAME .
Chad Grant