I am writing a scheduler component and I was planning to use Quartz.net. My requirements are:
- Have the scheduler running 24x7 (stopping/failing is acceptable, it would just need to start again)
- Be able to see what jobs/triggers are scheduled via a web page
- 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?