Question

As the title says, I can't get Quartz.NET to work at all. I've got the latest versions of Quartz.NET (2.2.1), common.logging (2.1.2), common.logging.nlog (2.0.0), and NLog (2.1.0) from NuGet. Triggers aren't firing and there's absolutely nothing getting logged by Quartz. I'm guessing I screwed up the config somehow.

My 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>

There's one job and one trigger associated with it:

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

The scheduler is started, the job and trigger are added properly, and logging works otherwise. The nextFireTime comes and goes and nothing happens.

The trigger creation code:

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

Solution

Based on your infos it should work; it should run once a day.

Make sure you have installed Common Logging NLog20]:

Install-Package Common.Logging.NLog20

And change this section:

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

and this should be your runtime section:

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

You can check the schedule of your trigger with this:

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

A full, working example can be found here (QuartzNetDailyAtHourAndMinute.zip).

OTHER TIPS

I have reproduced your issue, and this has worked for me:

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

Remove the .StartNow() and the trigger should fire.

Hope it helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top