This blog is for showcasing my way of implementing IJob interface of Quartz.net. IJob interface is needed for any class that needs to run in Quartz scheduler.
IJob interface has the following definition,
- namespace Quartz {
-
-
-
-
-
-
-
-
- public interface IJob {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- void Execute(IJobExecutionContext context);
- }
- }
If we try to take this interface and inherit it for other classes every class needs to implement Execute method which is not very manageable and brings a redundancy of code. So in order to avoid it I created an abstract class which inherits from IJob and has the implemented Execute Method. Let us name it AbstractJob
- namespace Quartz_Net_Example {
- public abstract class AbstractJob: IJob {
- public abstract void PreProcessing(IJobExecutionContext context);
- public abstract void PostProcessing(IJobExecutionContext context);
- public void Execute(IJobExecutionContext context) {
- PreProcessing(context);
-
- PostProcessing(context);
- }
- }
- }
Any job that inherits from Abstract Job needs to worry about execution of job and gets a standardized base class code. However it needs to override PreProcessing and Post Processing methods so that any changes can be incorporated. Another option is to make PreProcessing and PostProcessing virtual and any class inheriting it if it wants to override the default implementation can override it.
In this way I have tried to showcase how to implement IJob for Quartz.Net