Quartz.Net 作业存储查询

发布于 2024-11-17 17:41:24 字数 229 浏览 4 评论 0原文

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

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

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?

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

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

发布评论

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

评论(1

不即不离 2024-11-24 17:41:24

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

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

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

  <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>

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

更新

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

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

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

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

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

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

另一件要记住的事情是,您需要在 Web 和 Windows 服务之间共享您的作业,因此最好将其保留在单独的程序集中。

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

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.

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