当配置文件更改时,quartz.net 可以重新配置作业吗?

发布于 2024-10-15 02:07:54 字数 2179 浏览 5 评论 0原文

我正在使用 Quartz.Net 进行概念验证 一个相当简单的调度任务,我唯一的要求是重新启动服务,不需要重新配置quartz

这是测试代码

        var factory = new StdSchedulerFactory();
        var scheduler = factory.GetScheduler();
        scheduler.Start();

app.config中的相关数据

  <quartz>
<add key="quartz.scheduler.instanceName" value="QuartzScheduler" />
<!-- 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.type" value="Quartz.Simpl.RAMJobStore, Quartz" />
<add key="quartz.plugin.xml.type" value="Quartz.Plugin.Xml.JobInitializationPlugin, Quartz" />
<add key="quartz.plugin.xml.fileNames" value="quartz.config" />

我的作业配置文件

    <?xml version="1.0" encoding="UTF-8"?>
<quartz xmlns="http://quartznet.sourceforge.net/JobSchedulingData"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                version="1.0"
                overwrite-existing-jobs="true">

  <job>
    <job-detail>
      <name>jobName1</name>
      <group>jobGroup1</group>
      <description>jobDesciption1</description>
      <job-type>Jobs.MyJob, Jobs</job-type>
      <volatile>false</volatile>
      <durable>true</durable>
      <recover>false</recover>
    </job-detail>

    <trigger>
      <cron>
        <name>cronName1</name>
        <group>cronGroup1</group>
        <description>CronTriggerDescription</description>
        <job-name>jobName1</job-name>
        <job-group>jobGroup1</job-group>
        <cron-expression>0 0/1 * * * ?</cron-expression>
      </cron>

    </trigger>
  </job>
</quartz>

cron表达式有效并且每分钟执行一次作业,但如果我将表达式更改为 0 0/5 * * * ?在运行该服务时,它仍然每分钟都会触发。那么有没有办法配置 Quartz.net 以便它监听配置文件的文件更改?

Im doing a proof of concept with Quartz.Net
A fairly simple scheduling task, the only requirement i have is that a restart of the service it not needed to reconfigure quartz

This is test code

        var factory = new StdSchedulerFactory();
        var scheduler = factory.GetScheduler();
        scheduler.Start();

Relevant data in app.config

  <quartz>
<add key="quartz.scheduler.instanceName" value="QuartzScheduler" />
<!-- 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.type" value="Quartz.Simpl.RAMJobStore, Quartz" />
<add key="quartz.plugin.xml.type" value="Quartz.Plugin.Xml.JobInitializationPlugin, Quartz" />
<add key="quartz.plugin.xml.fileNames" value="quartz.config" />

My job config file

    <?xml version="1.0" encoding="UTF-8"?>
<quartz xmlns="http://quartznet.sourceforge.net/JobSchedulingData"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                version="1.0"
                overwrite-existing-jobs="true">

  <job>
    <job-detail>
      <name>jobName1</name>
      <group>jobGroup1</group>
      <description>jobDesciption1</description>
      <job-type>Jobs.MyJob, Jobs</job-type>
      <volatile>false</volatile>
      <durable>true</durable>
      <recover>false</recover>
    </job-detail>

    <trigger>
      <cron>
        <name>cronName1</name>
        <group>cronGroup1</group>
        <description>CronTriggerDescription</description>
        <job-name>jobName1</job-name>
        <job-group>jobGroup1</job-group>
        <cron-expression>0 0/1 * * * ?</cron-expression>
      </cron>

    </trigger>
  </job>
</quartz>

The cron expression works and teh job is executed each minute, but if i change the expression to 0 0/5 * * * ? while running the service it still fires each minute. So is there a way to config Quartz.net so that it listens to file changes to the config file?

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

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

发布评论

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

评论(1

债姬 2024-10-22 02:07:54

为插件添加扫描间隔定义(秒):

<add key="quartz.plugin.xml.scanInterval" value="10" />

之后插件将定期检查文件更改。

Add scan interval definition (seconds) for the plugin:

<add key="quartz.plugin.xml.scanInterval" value="10" />

After that plugin will periodically check for file changes.

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