我刚刚开始使用 Quartz .NET。首先,我开发了一些代码并在代码中安排了工作和触发器,效果很好:
var job = JobBuilder.Create<MetaFileEngine>()
.WithIdentity("MetaFileJob", "ThunderheadOutput")
.Build();
job.JobDataMap.Put("Repository", repository);
var trigger = (ICronTrigger)TriggerBuilder.Create()
.WithIdentity("trigger1", "group1")
.WithCronSchedule("0,15 * 06-22 * * ?")
.Build();
但为了更灵活,我想使用 XML 作业调度。但是当我运行它时,什么也没发生。我什至没有看到创建的工作,但也没有错误。
这是代码:
NameValueCollection properties = new NameValueCollection();
properties["quartz.scheduler.instanceName"] = "XmlConfiguredInstance";
// set thread pool info
properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
properties["quartz.threadPool.threadCount"] = "5";
properties["quartz.threadPool.threadPriority"] = "Normal";
// job initialization plugin handles our xml reading, without it defaults are used
properties["quartz.plugin.xml.type"] = "Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz";
properties["quartz.plugin.xml.fileNames"] = AppConfigHelper.Get("QaurtzXMLSchedule", string.Empty);
ISchedulerFactory sf = new StdSchedulerFactory(properties);
和我的xml:
<?xml version="1.0" encoding="UTF-8"?>
<job-scheduling-data xmlns="http://quartznet.sourceforge.net/JobSchedulingData"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.0" >
<processing-directives>
<overwrite-existing-data>true</overwrite-existing-data>
</processing-directives>
<schedule>
<job>
<name>MetaFileJob</name>
<group>ThunderheadOutput</group>
<description>process Metafiles generated by TH to tell where the letter was archived</description>
<job-type>JE.Task.LMS.MetaFileEngine, JE.Task.LMS</job-type>
<durable>false</durable>
<recover>false</recover>
<job-data-map>
<entry>
<key>key0</key>
<value>value0</value>
</entry>
<entry>
<key>key1</key>
<value>value1</value>
</entry>
<entry>
<key>key2</key>
<value>value2</value>
</entry>
</job-data-map>
</job>
<trigger>
<cron>
<name>MetaFileTrigger</name>
<group>ThunderheadOutput</group>
<description>MetaFileTrigger Schedule</description>
<job-name>MetaFileJob</job-name>
<job-group>ThunderheadOutput</job-group>
<misfire-instruction>SmartPolicy</misfire-instruction>
<cron-expression>0,15 * 06-22 * * ?</cron-expression>
</cron>
</trigger>
</schedule>
</job-scheduling-data>
任何见解将不胜感激。