Quartz.Net 作业存储查询 [英] Quartz.Net Job Storage Query

查看:57
本文介绍了Quartz.Net 作业存储查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在当前项目中使用 Quartz.NET 创建调度程序.就我而言,所有必须创建的作业都存储在一个表中,并且有一个单独的 UI,我可以在其中添加新作业或编辑现有作业.我的问题是如何将表中的所有作业提供给 Quartz 调度程序?我是否想查询表中的所有作业并遍历它以创建 JobDetails 和 Trigger 对象?在这种情况下有什么更好的方法吗?

在这种情况下,我想使用 RAMJobStore 还是 AdoJobStore?

解决方案

您可以使用 AdoJobStore.
Quartz.net 将在您的数据库中使用一组带有前缀 QRTZ_(您可以根据需要更改它)的表来存储这些对象的作业、触发器和状态.
我猜您想在您的数据库中有一个表,您将在其中保留有关您的日程安排的扩展信息,对吗?
您不会直接访问 Quartz.net 表,因为您将使用 Quartz.net 提供的 API.

创建作业详细信息和触发器的过程非常简单,并且在教程中有很好的描述.>

要将您的应用配置为使用 AdoJobStore,您必须在 app.config 文件中指定一些信息.下面是一个例子:

 <add key="quartz.scheduler.instanceName" value="myApp"/><add key="quartz.scheduler.instanceId" value="MyApp"/><!-- 配置线程池--><add key="quartz.threadPool.type"value="Quartz.Simpl.SimpleThreadPool, Quartz"/><add key="quartz.threadPool.threadCount" value="10"/><add key="quartz.threadPool.threadPriority" value="Normal"/><!-- 配置作业存储--><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.dataSource.default.connectionString"value="服务器=SVSQL2008;数据库=QuartzNet1;Trusted_Connection=True;"/><add key="quartz.dataSource.default.provider" value="SqlServer-20"/></石英>

根据您是在 Web 应用程序、服务或 winform 应用程序中托管 Quartz.net,有几件事需要牢记.最好的方法是将 SchedulerFactory 和 Scheduler 创建为单例.您可以在此处收集更多信息.

更新:

首先,您必须创建 Quartz.net 表(参见 第 1 步),然后您必须创建一些索引以进行优化(请参阅页面的底部).

由于您将使用 Web 应用程序提交作业,但您没有将该应用程序用于 Quartz.net 事件(触发器),因此您无需启动调度程序.这方面有几个步骤要遵循:

您必须将线程池类型更改为 ZeroSizeThreadPool

并且你必须定义你的 StdSchedulerFactory 和 Scheduler 单例.您可以在应用程序 (asp.net) 引导期间启动.

您永远不会启动调度程序(您的 Windows 服务将使用它).

要记住的另一件事是您需要在您的网络和 Windows 服务之间共享您的工作,因此最好将其保存在单独的程序集中.

您提到要在其中一张表中存储一些信息.您仍然需要提交您的作业和触发器,它们将持久保存在 Quartz.net 表中.

I'm creating a scheduler using Quartz.NET in the current project. In my case all the jobs that has to be created are stored in a single table and there is a separate UI where I can add new jobs or edit existing jobs. My question is how I can feed all the jobs in the table to the Quartz scheduler? Do I want to query for all the jobs in the table and iterate through it creating the JobDetails and Trigger objects? Is there any better way in this case?

In this case do I want to use a RAMJobStore or AdoJobStore?

解决方案

you can use AdoJobStore.
Quartz.net will use a set of tables with prefix QRTZ_ (you can change it if you want) in your database to stored jobs, triggers and status of these objects.
I guess you want to have a table in your DB where you're going to keep extended information about your schedules, right?
You won't access Quartz.net table directly cause you will use the APIs provided by Quartz.net.

The process to create a job detail and trigger is straightforward and described very well in the tutorials.

To configure your app to use the AdoJobStore you have to specify few informations in your app.config file. Here is an example:

  <quartz>
    <add key="quartz.scheduler.instanceName" value="myApp" />
    <add key="quartz.scheduler.instanceId" value="MyApp" />
    <!-- Configure Thread Pool -->
    <add key="quartz.threadPool.type" 
                  value="Quartz.Simpl.SimpleThreadPool, Quartz" />
    <add key="quartz.threadPool.threadCount" value="10" />
    <add key="quartz.threadPool.threadPriority" value="Normal" />
    <!-- Configure Job Store -->
    <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.dataSource.default.connectionString" 
        value="Server=SVSQL2008;Database=QuartzNet1;Trusted_Connection=True;" />
    <add key="quartz.dataSource.default.provider" value="SqlServer-20" />
   </quartz>

There are few things to keep in mind depending if you're hosting Quartz.net in a web application or a service or winform app. The best approach is to create SchedulerFactory and Scheduler as singleton. You can gather some more infos here.

UPDATE:

First of all you have to create Quartz.net tables (see Step 1) and then you'll have to create a few indexes for optiomization (see bottom of the page).

Since you're going to submit your jobs using the web app but you're not using that app for the quartz.net events (triggers) you don't need to start the scheduler. There are few steps to follow on this side:

you have to change the thread pool type to ZeroSizeThreadPool

<add key="quartz.threadPool.type" 
                   value="Quartz.Simpl.ZeroSizeThreadPool, Quartz" />

and you have to define your StdSchedulerFactory and Scheduler singleton. You can start during the application (asp.net) bootstrap.

You're never going to start the Scheduler (your windows service is going to use that).

Another thing to remember is you're going to need share your job between your web and your windows service, so it would be better to keep it in a separate assembly.

You mentioned you're storing some infos in one of your table. You still need to have to submit your jobs and trigger which will be persisted in Quartz.net tables.

这篇关于Quartz.Net 作业存储查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆