从 ASP.Net 应用程序检索 Quartz.net 作业信息

发布于 2024-09-08 21:27:54 字数 2993 浏览 4 评论 0原文

我们有一个 Quartz.Net 安装作为 Windows 服务运行。运行得很好。我们还有一个 ASP.Net 应用程序,可以添加/编辑作业并监视作业。我们偶尔会在 ASP.Net 应用程序中遇到错误。错误要么是“调度程序已关闭”。或“名为“JOB_SCHEDULER_NAME”的调度程序已存在。”

如果刷新页面,效果就很好。我已经能够通过一遍又一遍地快速打开同一页面的多个实例来重现该问题。所以,我目前的理论是,我们获取调度程序实例的方式不是线程安全的。

作为一个例子,下面是我们如何获取工作信息的简化版本:

var schedulerFactory = new StdSchedulerFactory();
var scheduler = schedulerFactory.GetScheduler();
var jobDetail = scheduler.GetJobDetail("SomeJobName", "SomeJobGroup");

这是在 ASP.Net 应用程序中加载页面时完成的。

ASP.Net 的配置设置是:

<quartz>
  <add key="quartz.scheduler.instanceName" value="COMPANY_NAME_JobScheduler" />
  <add key="quartz.scheduler.instanceId" value="Provider.DEV" />
  <add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz" />
  <add key="quartz.jobStore.useProperties" value="true" />
  <add key="quartz.jobStore.dataSource" value="default" />
  <add key="quartz.jobStore.tablePrefix" value="QRTZ_" />
  <add key="quartz.jobStore.lockHandler.type" value="Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz" />
  <add key="quartz.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz " />
  <add key="quartz.dataSource.default.connectionString" value="server=PROD_SQL_SERVER;uid=SQL_USER;pwd=SQL_PASSWORD;database=Scheduler" />
  <add key="quartz.dataSource.default.provider" value="SqlServer-20" />
</quartz>

Windows 服务正在初始化调度程序,如下所示:

var schedulerFactory = new StdSchedulerFactory();
var scheduler = schedulerFactory.GetScheduler();

Windows 服务配置是:

<quartz>
  <add key="quartz.scheduler.instanceName" value="COMPANY_NAME_JobScheduler" />
  <add key="quartz.scheduler.instanceId" value="Service.PROD" />

  <add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz" />
  <add key="quartz.threadPool.threadCount" value="10" />
  <add key="quartz.threadPool.threadPriority" value="2" />

  <add key="quartz.jobStore.misfireThreshold" value="60000" />
  <add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz" />
  <add key="quartz.jobStore.useProperties" value="true" />
  <add key="quartz.jobStore.dataSource" value="default" />
  <add key="quartz.jobStore.tablePrefix" value="QRTZ_" />
  <add key="quartz.jobStore.lockHandler.type" value="Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz" />
  <add key="quartz.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz " />

  <add key="quartz.dataSource.default.connectionString" value="server=PROD_SQL_SERVER;uid=SQL_USER;pwd=SQL_PASSWORD;database=Scheduler" />
  <add key="quartz.dataSource.default.provider" value="SqlServer-20" />
</quartz>

有更好的方法来“查询”调度程序吗?

编辑:添加了更多配置信息

We have a Quartz.Net installation running as a Windows Service. That's running fine. We also have a ASP.Net app that adds/edits jobs and monitors jobs. We occasionally get an error in the ASP.Net application. The errors are either "The Scheduler has been Shutdown." or "Scheduler with name 'JOB_SCHEDULER_NAME' already exists."

If you refresh the page, it works fine. I have been able to recreate the problem by quickly opening multiple instances of the same page over and over. So, my current theory is that the way we're getting an instance of the Scheduler is not thread-safe.

As an example, here is a simplified version of how we're getting job information:

var schedulerFactory = new StdSchedulerFactory();
var scheduler = schedulerFactory.GetScheduler();
var jobDetail = scheduler.GetJobDetail("SomeJobName", "SomeJobGroup");

This is being done when loading a page in the ASP.Net application.

The ASP.Net's config setup is:

<quartz>
  <add key="quartz.scheduler.instanceName" value="COMPANY_NAME_JobScheduler" />
  <add key="quartz.scheduler.instanceId" value="Provider.DEV" />
  <add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz" />
  <add key="quartz.jobStore.useProperties" value="true" />
  <add key="quartz.jobStore.dataSource" value="default" />
  <add key="quartz.jobStore.tablePrefix" value="QRTZ_" />
  <add key="quartz.jobStore.lockHandler.type" value="Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz" />
  <add key="quartz.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz " />
  <add key="quartz.dataSource.default.connectionString" value="server=PROD_SQL_SERVER;uid=SQL_USER;pwd=SQL_PASSWORD;database=Scheduler" />
  <add key="quartz.dataSource.default.provider" value="SqlServer-20" />
</quartz>

The Windows Service is initializing the scheduler like this:

var schedulerFactory = new StdSchedulerFactory();
var scheduler = schedulerFactory.GetScheduler();

The Windows Service config is:

<quartz>
  <add key="quartz.scheduler.instanceName" value="COMPANY_NAME_JobScheduler" />
  <add key="quartz.scheduler.instanceId" value="Service.PROD" />

  <add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz" />
  <add key="quartz.threadPool.threadCount" value="10" />
  <add key="quartz.threadPool.threadPriority" value="2" />

  <add key="quartz.jobStore.misfireThreshold" value="60000" />
  <add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz" />
  <add key="quartz.jobStore.useProperties" value="true" />
  <add key="quartz.jobStore.dataSource" value="default" />
  <add key="quartz.jobStore.tablePrefix" value="QRTZ_" />
  <add key="quartz.jobStore.lockHandler.type" value="Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz" />
  <add key="quartz.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz " />

  <add key="quartz.dataSource.default.connectionString" value="server=PROD_SQL_SERVER;uid=SQL_USER;pwd=SQL_PASSWORD;database=Scheduler" />
  <add key="quartz.dataSource.default.provider" value="SqlServer-20" />
</quartz>

Is there better way to "query" the scheduler?

Edit: added more config info

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

自找没趣 2024-09-15 21:27:54

我们已将调度程序设置为应用程序中的单例,这为我们解决了问题:

public class MyScheduler
{
    static MyScheduler()
    {
        _schedulerFactory = new StdSchedulerFactory(getProperties());
        _scheduler = _schedulerFactory.GetScheduler();
    }
    public static IScheduler GetScheduler()
    {
        return _scheduler;
    }

    private static readonly ISchedulerFactory _schedulerFactory;
    private static readonly IScheduler _scheduler;
 }

We've set up the scheduler to be a singleton in our application, which fixed the problem for us:

public class MyScheduler
{
    static MyScheduler()
    {
        _schedulerFactory = new StdSchedulerFactory(getProperties());
        _scheduler = _schedulerFactory.GetScheduler();
    }
    public static IScheduler GetScheduler()
    {
        return _scheduler;
    }

    private static readonly ISchedulerFactory _schedulerFactory;
    private static readonly IScheduler _scheduler;
 }
囍孤女 2024-09-15 21:27:54

不要让两个调度程序直接连接到数据库,而是尝试使 Web 调度程序连接到服务调度程序通过远程处理

Instead of having both schedulers connect directly to the database, try making the web scheduler connect to the service scheduler through remoting.

反目相谮 2024-09-15 21:27:54

正如莫里斯指出的,更好的方法可能是使用远程处理。您可以查看这个相关问题: 使用一个 Windows 服务来执行作业,使用两个 Web 应用程序来安排作业

As Maurice indicates, a better approach may be to use remoting. You can look at this related question: Use one windows service to execute jobs and two web applications to schedule jobs

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文