Question

I have a quartz_jobs.xml file that has jobs defined in it. I can load the quartz_jobs.xml file configuration and jobs start firing. Aka, "reading" the jobs from the quartz_jobs.xml file works fine.

However, if I manually add a job to the IScheduler, this manually added job will start running......(along with jobs defined in the quartz_jobs.xml file).... BUT the job is not ~written to the xml.

Is there a way to add a job to the IScheduler and have it write-back to the quartz_jobs.xml file?

Note, when I wired up the exact same code to a AdoStore, and I call the IScheduler.Start(), the jobs do get added to the database tables (aka, they persist). But the same code wired to a RamStore running against Xml does not "save" the jobs to the quartz_jobs.xml file.

Thanks.

Here is my quartz.config (not the jobs) file.

<quartz>

    <add key="quartz.plugin.jobInitializer.type" value="Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin" />
    <add key="quartz.scheduler.instanceName" value="DefaultQuartzScheduler" />
    <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" />
    <add key="quartz.plugin.jobInitializer.fileNames" value="quartz_jobs.xml" />
    <add key="quartz.plugin.jobInitializer.failOnFileNotFound" value="true" />
    <add key="quartz.plugin.jobInitializer.scanInterval" value="120" />


</quartz>

http://quartznet.sourceforge.net/apidoc/2.0/html/html/2909678f-44c6-6e13-afa5-c50e7b5ee435.htm

XMLSchedulingDataProcessorPlugin Class Quartz.NET API Documentation This plugin loads XML file(s) to add jobs and schedule them with triggers as the scheduler is initialized, and can optionally periodically scan the file for changes.

Was it helpful?

Solution

I don't think you can.

XMLSchedulingDataProcessor doesn't have any methods to serialize your jobs back to the file and QuartzXmlConfiguration20 seems to have only read-only collections.

I've tried to do some experiments.

Apparently you can manage to whole process of loading and processing the xml file:

ITypeLoadHelper loadHelper = new SimpleTypeLoadHelper();
loadHelper.Initialize();
XMLSchedulingDataProcessor processor = new XMLSchedulingDataProcessor(loadHelper);
processor.OverWriteExistingData = true;
processor.ProcessFileAndScheduleJobs("my_jobs.xml", Scheduler);

(so you do not have to use any configuration in your config file) but, again, there's no way to append extra elements.

Another way could be to deserialize the xml file and try to manipulate it:

string xml = string.Empty;

using (var xmlJobFile = new System.IO.StreamReader("my_jobs.xml"))
{
    xml = xmlJobFile.ReadToEnd();
}

XmlSerializer xs = new XmlSerializer(typeof(QuartzXmlConfiguration20));
QuartzXmlConfiguration20 data = (QuartzXmlConfiguration20)xs.Deserialize(new StringReader(xml));

if (data == null)
{
    throw new SchedulerConfigException("Job definition data from XML was null after deserialization");
}

But it gets too complicated.

I reckon that the best option is to use AdoJobStore.

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