Friday, August 18, 2006

Tell me when my scheduled jobs fail - Part II

Not long ago I posted about writing an EPiServer scheduled job that notifies me when scheduled jobs fail. I created a prototype, which works well, but is flawed in that if all scheduled jobs are failing (including my notifier), then I won't know about it. So as a result I started thinking of other ways this could be done.

In my thinking I came up with two other possibilities. The first thought is to use log4Net, and the other is to create a Windows Service.

Using log4Net
Using log4Net is probably the best solution for this sort of thing as it's already part of all EPiServer sites, and to setup notification of errors is just a configuration task. By implementing an SmtpAppender and a logger on the EPiServer.DataAbstraction.ScheduledJob namespace, you can quickly and easily setup email notifications about scheduled job failures.

Here's a sample section from the config file that I got working in my sample site:

<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
<to value="errors@domain.com"/>
<from value="errors@domain.com"/>
<subject value="Error encountered in EPiServer461 scheduled job" />
<smtpHost value="127.0.0.1" />
<bufferSize value="512" />
<lossy value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d\t%X{siteid}\t%m%n" />
</layout>
</appender>

<logger name="EPiServer.DataAbstraction.ScheduledJob">
<level value="ERROR" />
<appender-ref ref="SmtpAppender" />
</logger>


Using a Windows Service
With a Windows Service I could either hook directly into the EPiServer database and query the job history, but the better thing to do would be to create a web service in the website. The web service could use the EPiServer API the same as the scheduled job and return a dataset of failed jobs (or something like that).

The advantage of using a Windows Service is that the one service could be configured to interrogate multiple EPiServer sites and provide a summary email for all the sites.

This option would obviously require a lot more work as a Windows Service and Web service would need to be created. However, with this approach you could get a lot more flexibility and could customise the email to be a bit friendlier, and with more information.

EPiServer Scheduled Job
If you are interested in the scheduled job prototype that I created, then you can download it from here. It is pretty simple and all I was going to add was some filtering based on when the job last ran. This is so you wont get repeating notifications.

2 comments:

Anonymous said...

The download link does not work. "User is not allowed to use direct links" :-)

Gotta be a Web 2.0 app, I'm sure.

Jeremy said...

Try it again. I signed up for this free online storage account, but they obviously don't allow direct downloads.

The link now takes you to a public page where you can then download it.