如何在Quartz.NET 2.0中将Cron misfire指令FireOnceNow与AdoJobStore一起使用? [英] How to use cron misfire-instruction FireOnceNow with AdoJobStore in Quartz.NET 2.0?

查看:118
本文介绍了如何在Quartz.NET 2.0中将Cron misfire指令FireOnceNow与AdoJobStore一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在通过AdoJobStore设置并使用XMLSchedulingDataProcessorPlugin.

I am using a cron trigger with misfire-instruction set to FireOnceNow in quartz.net-2.0 set up with AdoJobStore and using XMLSchedulingDataProcessorPlugin.

cron-expression已设置,因此作业将每1分钟触发一次:0 0/1 * * * ?.

cron-expression is set so the job will trigger every 1 minute: 0 0/1 * * * ?.

作业计划程序设置为从Global.asax.cs开始.

The job scheduler is set to start in Global.asax.cs.

预期的行为:如果在应触发作业时服务器已停止,但在下一次触发之前已重新启动,则应立即触发一次.

Expected behaviour: If the server is stopped when a job should trigger but it is restarted before the next trigger then it should trigger once immediately.

示例:

第一个作业在 00:01:00 触发.

我在 00:02:00 可以触发之前就停止了服务器,但是应该在它应该触发后的几秒钟内启动它,例如 00:02:10 .

I stop the server before 00:02:00 can trigger but start it a few seconds after it should, let's say 00:02:10.

当我重新启动服务器(在 00:02:10 时)时,我希望在 00:02:00 处未触发的作业将触发一次然后恢复正常触发行为将继续.

When I restart the server (at 00:02:10) I would expect for the job that misfired at 00:02:00 would fire once and then normal trigger behavior would continue.

真正发生的事情是什么都不会触发.它只是从 00:03:00 继续触发.

What really happens is that nothing triggers. It just continues triggering from 00:03:00.

有什么想法可以使它按预期工作吗?

Any ideas what I have to do to make it work as expected?

感谢您的帮助!

@ Global.asax.cs:

@Global.asax.cs:

private IScheduler scheduler;

protected void Application_Start(object sender, EventArgs e)
{
    var factory = new StdSchedulerFactory();
    scheduler = factory.GetScheduler();
    scheduler.Start();
}

@ quartz_jobs.xml:

@quartz_jobs.xml:

<?xml version="1.0" encoding="UTF-8"?>
<job-scheduling-data xmlns="http://quartznet.sourceforge.net/JobSchedulingData"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     version="2.0">
  <processing-directives>
    <overwrite-existing-data>true</overwrite-existing-data>
  </processing-directives>
  <schedule>
    <job>
      <name>TestJob</name>
      <group>Default</group>
      <job-type>BO.TestJob, BO</job-type>
      <durable>true</durable>
      <recover>true</recover>
    </job>
    <trigger>
      <cron>
        <name>TestCron</name>
        <group>Default</group>
        <job-name>TestJob</job-name>
        <job-group>Default</job-group>
        <misfire-instruction>FireOnceNow</misfire-instruction>
        <cron-expression>0 0/1 * * * ?</cron-expression>
      </cron>
    </trigger>
  </schedule>
</job-scheduling-data>

@ web.config:

@web.config:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
    <sectionGroup name="common">
      <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
    </sectionGroup>
  </configSections>
  <appSettings>
    <add key="log4net.Internal.Debug" value="false"/>
  </appSettings>
  <common>
    <logging>
      <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
        <arg key="configType" value="INLINE"/>
        <arg key="configFile" value="Trace/application.log.txt"/>
        <arg key="level" value="ALL" />
      </factoryAdapter>
    </logging>
  </common>
  <log4net>
    <appender name="GeneralLog" type="log4net.Appender.RollingFileAppender">
      <file value="Trace/application.log.txt"/>
      <appendToFile value="true"/>
      <maximumFileSize value="1024KB"/>
      <rollingStyle value="Size"/>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%d{HH:mm:ss} [%t] %-5p %c - %m%n"/>
      </layout>
    </appender>
    <root>
      <level value="ALL"/>
      <appender-ref ref="GeneralLog"/>
    </root>
  </log4net>
  <quartz>
    <add key="quartz.scheduler.instanceName" value="TestQuartzServer" />
    <add key="quartz.scheduler.instanceId" value="instance_one" />
    <add key="quartz.threadPool.threadCount" value="10" />
    <add key="quartz.threadPool.threadPriority" value="Normal" />
    <add key="quartz.jobStore.misfireThreshold" value="3000" />
    <add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz" />
    <add key="quartz.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.StdAdoDelegate, Quartz" />
    <add key="quartz.jobStore.useProperties" value="false" />
    <add key="quartz.jobStore.dataSource" value="default" />
    <add key="quartz.jobStore.tablePrefix" value="qrtz_" />
    <add key="quartz.jobStore.lockHandler.type" value="Quartz.Impl.AdoJobStore.SimpleSemaphore, Quartz" />
    <add key="quartz.dataSource.default.connectionStringName" value="PostgreSqlDb" />
    <add key="quartz.dataSource.default.provider" value="Npgsql-20" />
    <add key="quartz.plugin.xml.type" value="Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz" />
    <add key="quartz.plugin.xml.fileNames" value="~/quartz_jobs.xml" />
    <add key="quartz.plugin.xml.scanInterval" value="10" />
  </quartz>
  <connectionStrings>
    <add name="PostgreSqlDb" connectionString="Server=localhost;database=quartz_net;User ID=*****;Password=*****;" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
</configuration>

@ TestJob.cs:

@TestJob.cs:

using System;
using System.Diagnostics;
using Quartz;

namespace BO
{
    public class TestJob : IJob
    {
        public void Execute(IJobExecutionContext context)
        {
            Debug.WriteLine("@{0}: {1}", DateTime.Now, context.JobDetail.Key);
        }
    }
}

推荐答案

问题是,quartz_jobs.xml的每次自动处理都会覆盖失火操作正常运行所需的触发数据.

The problem was that the trigger data required for misfire action to work properly was overridden on each automatic processing of quartz_jobs.xml.

因此,将overwrite-existing-data设置为false是触发失败后触发器起作用的必要条件:

So setting overwrite-existing-data to false was required for the trigger to work after misfire:

<processing-directives>
  <overwrite-existing-data>false</overwrite-existing-data>
  <ignore-duplicates>true</ignore-duplicates>
</processing-directives>

这篇关于如何在Quartz.NET 2.0中将Cron misfire指令FireOnceNow与AdoJobStore一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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