quartz.net开了两枪

本文关键字:两枪 net quartz | 更新日期: 2023-09-27 17:58:26

我在asp.net mvc应用程序中集成了quartz.net。

我安排它每天凌晨运行一次。大多数时候,我的Sample工作会触发2次

2011-06-06 04:00:00.0077|INFO| -> once
2011-06-06 04:00:00.0233|INFO| -> twice

但它只发生过一次火灾,但很少(实际上只有一次)。

我很想弄清楚为什么会发生这种情况,或者关于如何解决此事件的建议(它发生在托管环境中)

这些是集成点:

Global.Asax.cs

protected void Application_Start()
{
ISchedulerFactory factory = new StdSchedulerFactory()    
IScheduler scheduler = factory.GetScheduler();    
scheduler.Start();    
}

web.config

  <configSections>
    <section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </configSections>
  <quartz>
     <add key="quartz.scheduler.instanceName" value="JobScheduler" />
    <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.Simpl.RAMJobStore, Quartz" />

    <add key="quartz.plugin.xml.type" value="Quartz.Plugin.Xml.JobInitializationPlugin, Quartz" />
    <add key="quartz.plugin.xml.fileNames" value="~/jobs.config" />
  </quartz>

jobs.config

<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>SampleJob</name>
       <group>SampleJobs</group>
       <description>sample</description>
      <job-type>Services.SampleJob, Sample</job-type>
      <volatile>false</volatile>
      <durable>true</durable>
      <recover>false</recover>
    </job-detail>
    <trigger>
      <cron>
        <name>SampleJobTrigger</name>
        <group>SampleJobs</group>
        <description>Description</description>
        <job-name>SampleJob</job-name>
        <job-group>SampleJobs</job-group>
        <cron-expression>0 0 4 * * ? *</cron-expression>
      </cron>
    </trigger>
   </job>
</quartz>

任何帮助或指示都会大大影响

--MB

quartz.net开了两枪

真的很难说。一切似乎都很好
我建议你让你的工厂和调度器成为单一的(这是应该的),看看会发生什么:

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

如果我们想将一些属性传递给调度程序,我们可以使用配置文件或:

private static NameValueCollection getProperties()
{
    var properties = new NameValueCollection();
    properties["quartz.scheduler.instanceName"] = "MyScheduler";
    properties["quartz.scheduler.instanceId"] = "Web";
    // Configure Thread Pool 
    properties["quartz.threadPool.type"] = "Quartz.Simpl.ZeroSizeThreadPool, Quartz";
    // Configure Job Store -->
    properties["quartz.jobStore.misfireThreshold"] = "60000";
    properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";
    properties["quartz.jobStore.lockHandler.type"] = "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz";
    properties["quartz.jobStore.useProperties"] = "true";
    properties["quartz.jobStore.dataSource"] = "default";
    properties["quartz.jobStore.tablePrefix"] = "QRTZ_";
    properties["quartz.jobStore.lockHandler.type"] = "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz";
    properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz";
    properties["quartz.dataSource.default.provider"] = "SqlServer-20";
    properties["quartz.dataSource.default.connectionString"] = "<connection string>";   
    return properties;
}

您的作业运行得非常快。

尝试添加一个System.Threading.Thread.Sleep(1000),将只激发一次。

谢谢!

这是一张旧的、已应答的票证。但我今天在测试环境中遇到了这种情况,并找出了可能的原因。

我们运行多个应用程序服务器。作业应该只从App1运行。但不知怎么的,App2的配置被踩了,所以它不仅运行作业,还写入App1的日志文件。

因此,看起来App1运行了两次作业,间隔几毫秒。这正是最初的帖子所看到的。