2014-01-29 236 views
1

正如标题所说,我不能让Quartz.NET在所有的工作。我有Quartz.NET(2.2.1)的最新版本,common.logging(2.1.2),common.logging.nlog(2.0.0),并从的NuGet NLOG(2.1.0)。触发器没有触发,Quartz没有任何记录。我猜我搞砸了配置。Quartz.NET:触发器没有得到触发,没有得到记录

我的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(); 
+0

你如何创建你的触发器,你能告诉我们cron表达式吗? – LeftyX

+0

我已经更新与创建触发器的代码的问题。 –

+1

需要更多代码来重现问题:jobDetails声明(它来自哪里)以及如何将作业/触发器对添加到调度程序。 – cvbarros

回答

0

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

确保你已经安装了通用日志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); 
    } 
} 

完整,工作实例可以发现hereQuartzNetDailyAtHourAndMinute.zip)。

0

我已复制您的问题,这也为我工作:

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

取出.StartNow()和触发应该火。

希望它有帮助!