本文介绍了使用一个 Windows 服务来执行作业,使用两个 Web 应用程序来调度作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 SQL Server 数据库作为作业存储、两个都可以调度作业的 Web 应用程序和一个执行作业的 Quartz.NET Windows 服务.

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.

我希望这两个 Web 应用程序只安排作业,而 Windows 服务只执行作业.

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

问题来了:

如果我在两个 web 应用程序和 windows 服务中创建 IScheduler 实例,它们将同时执行作业,可能会发生冲突.

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.

如果我不在这两个 Web 应用程序中创建 IScheduler 实例,如何从 Web 应用程序将作业调度到 Windows 服务?

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

有没有办法让 IScheduler 只调度作业而不执行作业?(我可以将 IJob 程序集部署到所有这三个应用程序)

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)

推荐答案

您可能不想在网站中实例化 IScheduler 实例,正是因为创建本地实例也会执行作业.

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.

首先,确保在您的服务配置文件(app.config)中配置了四个键quartz.scheduler.exporter.typequartz.scheduler.exporter.portquartz.scheduler.exporter.bindNamequartz.scheduler.exporter.channelType.

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.

第二,确保你的web.config配置了以下四个键:quartz.scheduler.instanceNamequartz.scheduler.instanceIdquartz.scheduler.proxyquartz.scheduler.proxy.address.

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.

然后,当您创建 StdSchedulerFactory() 并使用它来获取调度程序时,您不是在实例化新的调度程序,而是附加到现有的调度程序.然后,您可以通过远程调度程序执行本地调度程序可以执行的任何操作,但只有一个实例执行作业.

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.

这篇关于使用一个 Windows 服务来执行作业,使用两个 Web 应用程序来调度作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-29 00:15
查看更多