简体   繁体   中英

Quartz.net scheduler does not take latest changes to Jobs class file

In our asp.net web forms application we have daily jobs that need to send some emails to users.

Recently we started to use Quartz.net to allow jobs run non-sequentially. I am using the ADO Job store to schedule the jobs and create the triggers. While creating the job data I am also giving the.dll(full path) and the class name that has to be executed for that job. This is a console application that is run only once.

IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();

JobDataMap jobData = new JobDataMap();
jobData.Add("JobID", jobDataRow["Id"].ToString());
jobData.Add("AssemblyName", assemblyName);
jobData.Add("ClassName", className);
jobData.Add("AssemblyPath", assemblyPath);

 var jobDetail = JobBuilder.Create()
                       .StoreDurably()
                       .WithIdentity(name)
                       .SetJobData(jobData)
                       .Build(); ;

ITrigger trigger = TriggerBuilder.Create()
                       .WithIdentity(triggerName)
                       .WithCronSchedule(cronexpr)
                       .StartNow()
                       .Build();
scheduler.ScheduleJob(jobDetail, trigger, true);

Then we have a windows service that starts the scheduler. This windows service is stopped and restarted after every build.

StdSchedulerFactory schedulerFactory = new 
StdSchedulerFactory(schedulerProperties);
scheduler = schedulerFactory.GetScheduler();
scheduler.Start();

Quartz properties declared:-

<add key="quartz.threadPool.threadCount" value="10" />
    <add key="quartz.threadPool.threadPriority" value="2" />
    <add key="quartz.jobStore.misfireThreshold" value="60000" />
     <add key="quartz.scheduler.instanceId" value="Auto" />
    <add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz" />
    <add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz" />
    <add key="quartz.jobStore.dataSource" value="default" />
    <add key="quartz.jobStore.tablePrefix" value="QRTZ_" />
    <add key="quartz.jobStore.clustered" value="false" />
    <add key="quartz.jobStore.lockHandler.type" value="Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz" />
    <add key="quartz.dataSource.default.provider" value="SqlServer-20" />
    <add key="quartz.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz" />
    <add key="quartz.jobStore.useProperties" value="true" />
    <add key="quartz.jobStore.misfireThreshold" value="60000" />
    <add key="quartz.plugin.triggHistory.type" value="Quartz.Plugin.History.LoggingJobHistoryPlugin" />
    <add key="quartz.scheduler.exporter.type" value="Quartz.Simpl.RemotingSchedulerExporter, Quartz" />
    <add key="quartz.scheduler.exporter.port" value="555" />
    <add key="quartz.scheduler.exporter.bindName" value="QuartzScheduler" />
    <add key="quartz.scheduler.exporter.channelType" value="tcp" />
    <add key="quartz.scheduler.exporter.channelName" value="httpQuartz" />

Now the issue is - When any change is done to the class file like changes to the existing email template, the job still sends the emails using the old email template when run from Quartz scheduler.

If we run the job manually then the emails are sent correctly with the new changes.

Do we need to recreate the Quartz job data map(QRTZ_JOB_DETAILS table) every time when there is a change to the class files?

Please help.. I am stuck here and couldn't find any related post on this.

Thanks you in advance!!

If the Quartz process is already running and the DLL contents (jobs) have been loaded, they won't be automatically loaded again. This is how .NET CLR works. Once the process has loaded the type from givem DLL, it won't be reloaded by Quartz.

I don't know how you deployment process works, but I would see two options at least.

  1. Restart the process after you deploy new DLL version, sounds like basic deployment
  2. Make your jobs load templates from file system so you can change them in different cadence than what you use for the main process - but good release process would also update the binaries to the same level so this might not be the recommended approach

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM