Quartz.NET:触发器没有被触发,没有任何记录

时间:2014-01-29 20:14:59

标签: c# quartz.net quartz.net-2.0

正如标题所说,我无法让Quartz.NET工作。我从NuGet获得了最新版本的Quartz.NET(2.2.1),common.logging(2.1.2),common.logging.nlog(2.0.0)和NLog(2.1.0)。触发器没有触发,Quartz完全没有记录任何内容。我猜不到我搞砸了配置。

我的App.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    ...

    <section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" />

    <sectionGroup name="common">
      <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
    </sectionGroup>

  </configSections>

  <common>
    <logging>
      <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog">
        <arg key="configType" value="FILE" />
        <arg key="configFile" value="~/NLog.config" />
      </factoryAdapter>
    </logging>
  </common>

  <quartz>
    <add key="quartz.scheduler.instanceName" value="ServerScheduler" />

    <add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz" />
    <add key="quartz.threadPool.threadCount" value="10" />
    <add key="quartz.threadPool.threadPriority" value="2" />

    <add key="quartz.jobStore.misfireThreshold" value="60000" />
    <add key="quartz.jobStore.type" value="Quartz.Simpl.RAMJobStore, Quartz" />
  </quartz>

...

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
...
      <dependentAssembly>
        <assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.2.0" newVersion="2.1.2.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

有一个工作和一个与之相关的触发器:

{Trigger 'DEFAULT.DailyYahooUpdateTrigger':  triggerClass: 'Quartz.Impl.Triggers.CronTriggerImpl calendar: '' misfireInstruction: 0 nextFireTime: 01/29/2014 18:38:00 +00:00}
    [Quartz.Impl.Triggers.CronTriggerImpl]: {Trigger 'DEFAULT.DailyYahooUpdateTrigger':  triggerClass: 'Quartz.Impl.Triggers.CronTriggerImpl calendar: '' misfireInstruction: 0 nextFireTime: 01/29/2014 18:38:00 +00:00}
    CalendarName: null
    Description: null
    EndTimeUtc: null
    FinalFireTimeUtc: null
    HasMillisecondPrecision: false
    JobDataMap: {Quartz.JobDataMap}
    JobKey: {DEFAULT.DailyYahooUpdate}
    Key: {DEFAULT.DailyYahooUpdateTrigger}
    MisfireInstruction: 0
    Priority: 5
    StartTimeUtc: {29/1/2014 18:37:44 +00:00}

启动调度程序,正确添加作业和触发器,否则日志记录工作正常。 nextFireTime来来往往没有任何反应。

触发器创建代码:

    ITrigger trigger = TriggerBuilder
        .Create()
        .WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(jobDetails.Time.Hours, jobDetails.Time.Minutes))
        .StartNow()
        .WithIdentity(jobDetails.Name + "Trigger")
        .Build();

2 个答案:

答案 0 :(得分:0)

我已经复制了你的问题,这对我有用:

ITrigger trigger = TriggerBuilder
    .Create()
    .WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(jobDetails.Time.Hours, jobDetails.Time.Minutes))
    .WithIdentity(jobDetails.Name + "Trigger")
    .Build();

删除.StartNow(),触发器应该触发。

希望它有所帮助!

答案 1 :(得分:0)

根据您的信息,它应该工作;它应该每天运行一次。

确保已安装Common Logging NLog20]:

Install-Package Common.Logging.NLog20

并更改此部分:

  <common>
    <logging>
      <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog20">
        <arg key="configType" value="FILE" />
        <arg key="configFile" value="~/NLog.config" />
      </factoryAdapter>
    </logging>
  </common>

这应该是你的运行时部分:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

您可以使用以下方法检查触发器的计划:

private static void GetNext10FireTimes(ITrigger trigger)
{
    Console.WriteLine("List of next 10 schedules: ");

    var dt = trigger.GetNextFireTimeUtc();

    for (int i = 0; i < 10; i++)
    {
    if (dt == null)
        break;

    Console.WriteLine(dt.Value.ToLocalTime());

    dt = trigger.GetFireTimeAfter(dt);
    }
}

可以找到一个完整的工作示例here QuartzNetDailyAtHourAndMinute.zip )。