Use one windows service to execute jobs and two web applications to schedule jobs

谁都会走 提交于 2019-11-27 07:26:37

问题


I have one SQL Server database as the job store, two web applications that both can schedule jobs, and a Quartz.NET windows service to execute jobs.

I want the two web applications to just schedule jobs, while the windows service just to execute jobs.

Here comes the problem:

If I create IScheduler instances in the two web applications and in the windows service, they will execute jobs at the same time, there can be conflicts.

If I do not create IScheduler instances in the two web applications, how can I schedule jobs to the windows service from web applications?

Is there a way to let the IScheduler to just schedule jobs without executing jobs? (I can deploy the IJob assemblies to all these three applications)


回答1:


You probably don't want to instantiate an IScheduler instance in the websites, precisely because creating a local instance also executes jobs.

I've implemented something similar to what you're looking to do.

First, make sure that in your service configuration file (app.config) that you configure the four keys quartz.scheduler.exporter.type, quartz.scheduler.exporter.port, quartz.scheduler.exporter.bindName, and quartz.scheduler.exporter.channelType.

Second, make sure that your web.config has the following four keys configured : quartz.scheduler.instanceName, quartz.scheduler.instanceId, quartz.scheduler.proxy, and quartz.scheduler.proxy.address.

Then when you create your StdSchedulerFactory() and use it to get a scheduler, you are not instantiating a new scheduler, but attaching to an existing scheduler. You can then do anything through the remote scheduler that you could do with a local one, but there is only a single instance that executes jobs.




回答2:


In your config file, set key "quartz.threadPool.type" to "Quartz.Simpl.ZeroSizeThreadPool, Quartz". The quartz scheduler thus created can schedule/modify jobs/trigger/calendars but can not run the jobs.



来源:https://stackoverflow.com/questions/11968884/use-one-windows-service-to-execute-jobs-and-two-web-applications-to-schedule-job

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!