开发者

quartz.net fires twice

I have quartz.net integrated in asp.net mvc app.

I have it scheduled to run once a day in the early morning hours. Most of the times, my Sample job fires 2 times

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

But it has happened that it fires only once, but rarely (only once actually).

I am curious to figure out why this is happening, or also in suggestions on how to troubleshoot this event (it happens in a hosted environment)

These are points of integration:

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-ty开发者_StackOverflow中文版pe>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>

Any help or pointers greatly appriciated

--MB


It's hard to say, really. Everything seems all right.
I would suggest you to make your factory and scheduler singleton (that's the way it should be) and see what happens:

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

If we want to pass some properties to our scheduler we can use the config file or:

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


Your job are running very fast.

Try adding a System.Threading.Thread.Sleep(1000) and will fire only one time.

Thank you!


This is an old, and answered, ticket. But I ran into this in the Test environment today and hunted down a possible cause.

We run multiple app servers. The jobs are supposed to only run from App1. But somehow App2's config got stepped on so it was not only running the jobs but also writing to App1's log files.

So it looked like App1 was running the jobs twice, milliseconds apart. Exactly what the original post was seeing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜