Question

I am writing a scheduler component and I was planning to use Quartz.net. My requirements are:

  1. Have the scheduler running 24x7 (stopping/failing is acceptable, it would just need to start again)
  2. Be able to see what jobs/triggers are scheduled via a web page
  3. Be able to add new jobs/triggers via a web page


Since I need a scheduler running constantly, I planned to have a Windows service. Unfortunately, there does not appear to be any way to have the web pages interact with the scheduler running in the Windows service. I attempted to retrieve an instance with the following code put together from examples by Turan Arora:

        NameValueCollection properties = new NameValueCollection();
        properties["quartz.scheduler.instanceName"] = "ServerScheduler";

        // set thread pool info
        properties["quartz.threadPool.threadCount"] = "0";

        // set remoting expoter
        properties["quartz.scheduler.proxy"] = "true";
        properties["quartz.scheduler.proxy.address"] = "tcp://localhost:555/QuartzScheduler";

        // get a reference to the scheduler
        ISchedulerFactory sf = new StdSchedulerFactory(properties);
        IScheduler sched = sf.GetScheduler();


Going this route gives me an error saying: "Scheduler with name 'ServerScheduler' already exists." (ServerScheduler is the default scheduler name.) After some reading, it appears that the solution is to implement a singleton pattern to instanciate and return this instance throughout the lifecycle of the scheduler.

This does not seem like the ideal solution because I wanted two pieces--a scheduler Windows service and a web site. Clearly the web site should not own the scheduler because for one thing it may or may not be in use 24x7 and I need the scheduled jobs to be able to execute 24x7. Second, I don't think I want my web site communicating back to a Windows service to get a reference to the scheduler to get this information.

I believe I am misunderstanding the architecture using Quartz.net in this situation. But, if I am correct, maybe the solution is to maintain a relational data store that Quartz.net can read to get its jobs, and the web site can also read to see what is executing. I want a relational data store to persist the jobs and triggers anyway, so maybe this is the best means of providing the data between the two applications?

Was it helpful?

Solution

What you want to do in this case is either connect via remoting like you've tried, just make sure if you are running Quartz.NET processes in the same machine that you have different instance names.

If you already are decided with running using AdoJobStore then one easy option is to connect from web app to the same job store without actually starting the scheduler. You can query and modify the job store jobs and triggers from web app and let the service run the actual triggering of jobs. Here's an answer related to described scenario.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top