誰かがQuartzxmlの私の簡単なテスト(毎秒起動)を見て、シェデュラーにジョブが追加されていない理由の手がかりを教えてもらえますか?基本的に、「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);
}
}
}
}