有人可以看看我对 Quartz xml 的简单测试(每秒触发一次),并给我一个线索,为什么没有工作被添加到调度程序中?基本上我希望'SimpleJob'类每秒被触发一次,我可以确定正在传递哪个作业以及以键的形式传递哪些参数 - 老实说,我很困惑,因为没有足够的文档
<job>
<name>jobName1</name>
<group>jobGroup1</group>
<description>jobDesciption1</description>
<job-type>Quartz.Job.NoOpJob, Quartz</job-type>
<durable>true</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>simpleName</name>
<group>simpleGroup</group>
<description>SimpleTriggerDescription</description>
<job-name>jobName1</job-name>
<job-group>jobGroup1</job-group>
<cron-expression>1 * * * * ?</cron-expression>
<time-zone></time-zone>
</cron>
</trigger>
几个问题: 1. 我想启动一个带有 2 个参数的控制台应用程序 - 我将如何实现?2. 在 job-data-map 部分,我可以添加多个键/值,但值是什么?我是添加可执行文件还是在另一个类中使用键/值对,我猜是
class Program
{
static void Main(string[] args)
{
// First we must get a reference to a scheduler
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"] = @"c:\users\paul\documents\visual studio 2010\Projects\ShedulerService\ShedulerApplication\quartz_jobs.xml"; //"~/quartz_jobs.xml";
ISchedulerFactory sf = new StdSchedulerFactory(properties);
IScheduler sched = sf.GetScheduler();
// we need to add calendars manually, lets create a silly sample calendar
//var dailyCalendar = new DailyCalendar("00:01", "23:59");
//dailyCalendar.InvertTimeRange = true;
//sched.AddCalendar("cal1", dailyCalendar, false, false);
// all jobs and triggers are now in scheduler
// Start up the scheduler (nothing can actually run until the
// scheduler has been started)
sched.Start();
// wait long enough so that the scheduler as an opportunity to
// fire the triggers
try
{
Thread.Sleep(30 * 1000);
}
catch (ThreadInterruptedException)
{
}
sched.Shutdown(true);
SchedulerMetaData metaData = sched.GetMetaData();
Console.WriteLine("Executed " + metaData.NumberOfJobsExecuted + " jobs.");
Console.Read();
}
public class SimpleJob : IJob
{
public virtual void Execute(IJobExecutionContext context)
{
// This job simply prints out its job name and the
// date and time that it is running
JobKey jobKey = context.JobDetail.Key;
if (context.MergedJobDataMap.Count > 0)
{
ICollection<string> keys = context.MergedJobDataMap.Keys;
foreach (string key in keys)
{
String val = context.MergedJobDataMap.GetString(key);
//log.InfoFormat(" - jobDataMap entry: {0} = {1}", key, val);
Console.WriteLine("jobDataMap entry: {0} = {1}", key, val);
}
}
}
}