views:

7

answers:

1

This link suggests to create an abstract base class that can read the job data map information for Quartz.net and each of the jobs will derive from this base class.

http://quartznet.sourceforge.net/faq.html#howtochainjobs

Can someone provide me a sample of this base class because I am not sure how to retrieve the job details in the base class and then call the Execute method on the derived class?

Pratik

A: 

Hi Pratik,

Creating an abstract base class is just a suggestion made by the Quartz.NET documentation, and is not a requirement for implementing job chaining. Basically they are suggesting that if you want to chain jobs: "AJob" -> "BJob" -> "CJob", you would do something along the lines of this:

  1. Create abstract class "ChainBaseJob".

  2. Make your job class (which both AJob and BJob are types of) inherit from ChainBaseJob.

  3. ChainBaseJob would contain some sort of method like:

        string GetNextJobInChain()
    

...which would return the name of the job (meaning the Quartz job name). There's a variety of ways to do use this, but I guess the documentation is suggesting that your TriggerListener checks to see (during the job completed method) if a completed job (let's say "AJob") inherits from ChainBaseJob. If it does, it will cast it and call GetNextJobInChain, and use the name returned by the method to call the scheduler to execute it upon completion of AJob. If everything is implemented correctly, the TriggerListener will know to execute BJob, after AJob completes.

Good luck.

warriorpostman
Thank you very much for the explanation. If I do make this base class abstract, how can I read the job data map for the job in the base class. The thing is each of my job pretty much have the same job detail like the email address, user id so I would like to read these values in the base class properties so I don't have to repeat this code in every derived class. If I made the base class non-abstract, then I can call the base class's constructor from derived class's constructor and read the properties.I would like to learn that if the base class is abstract, then how can I achieve this.
Pratik Kothari
Here is how I did it.public abstract class QuartzJobBase: IJob{ public int A { get; set; } public void Execute (JobExecutionContext context) { JobDataMap dataMap = context.JobDetail.JobDataMap; A = dataMap.GetInt("a"); ExecuteInternal(context); } public abstract void ExecuteInternal(JobExecutionContext context);}}In the derived class for each job, override the ExecuteInternal method.
Pratik Kothari