RAMJobStore (quartz_jobs.xml) to AdoJobStore Data Move
Asked Answered
A

1

1

My team and I are trying to figure out a way to "load up" our Sql Server database with the Quartz.NET schema installed.

<add key="quartz.dataSource.default.provider" value="SqlServer-20"/>

For demo's, we've been storing our job-setups in .xml (quartz_jobs.xml).

My question is :

Is there a way to "load up" the scheduling data from .xml (quartz_jobs.xml) (Quartz.Simpl.RAMJobStore), and then "save it off" to a AdoJobStore (Quartz.Impl.AdoJobStore.JobStoreTX) ?

The reason is that our "start up" data could be easily written placed in the .xml.

Right now, the only way I see putting jobs into a AdoJobStore is "coding them up" in c# code through the Quartz.Net object model.

Or "playing back" some profiled TSQL (using Sql Profiler) :(

Direct question is above "(getting xml into sql-server)".....the higher level question is "How does one populate a AdoJobStore with start up data...that isn't "coding them up" in c# code.

EDIT: I'm putting in my code that works......using Marko's (accepted as the answer) response.

My configuration file:

<quartz>

    <add key="quartz.plugin.xml.type" value="Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz" />
    <add key="quartz.plugin.xml.fileNames" value="~/Quartz_Jobs_001.xml" />
    <add key="quartz.plugin.xml.ScanInterval" value="10" />

    <add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz" />
    <add key="quartz.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz"/>
    <add key="quartz.jobStore.dataSource" value="default"/>
    <add key="quartz.dataSource.default.connectionString" value="Server=MyServer\MyInstance;Database=QuartzDB;Trusted_Connection=True;Application Name='quartz_config';"/>
    <add key="quartz.dataSource.default.provider" value="SqlServer-20"/>

</quartz>

My code:

    NameValueCollection config = (NameValueCollection)ConfigurationManager.GetSection("quartz");
    ISchedulerFactory factory = new StdSchedulerFactory(config);
    IScheduler sched = factory.GetScheduler();
    sched.Clear();
    sched.Start();

NOTE:

I had to call IScheduler.Start() for the values to persist to the database.

The consequence of adding this line:

 <add key="quartz.plugin.xml.ScanInterval" value="10" />

was that I could add entries into the quartz_job.xml, and it would would (append-only) the data in the database (while the engine was running).

Aka, I can "add lookup data" (to the database) "on the fly"....without stopping the service. A nice little tidbit. Removing a job requires a restart.

Angkor answered 5/2, 2014 at 22:29 Comment(0)
Y
3

You should be able to do this quite easily. You can combine the XML configuration and ADO job store. This will make the XML processor update the jobs in the persistent store.

Here's minimal configuration:

NameValueCollection properties = new NameValueCollection();

properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";
properties["quartz.jobStore.dataSource"] = "default";
properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz";

properties["quartz.dataSource.default.connectionString"] = "Server=(local);Database=quartz;Trusted_Connection=True;";
properties["quartz.dataSource.default.provider"] = "SqlServer-20";

// 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"] = "~/quartz_jobs.xml";

// First we must get a reference to a scheduler
ISchedulerFactory sf = new StdSchedulerFactory(properties);
IScheduler sched = sf.GetScheduler();

And our XML configuration contains overwrite instructions so that job store is refreshed:

<?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>jobName1</name>
      <group>jobGroup1</group>
      <description>jobDesciption1</description>
      <job-type>Quartz.Examples.Example15.SimpleJob, Quartz.Examples</job-type>
      <durable>true</durable>
      <recover>false</recover>
    </job>

    <trigger>
      <simple>
        <name>simpleName</name>
        <group>simpleGroup</group>
        <description>SimpleTriggerDescription</description>
        <job-name>jobName1</job-name>
        <job-group>jobGroup1</job-group>
        <start-time>1982-06-28T18:15:00.0Z</start-time>
        <repeat-count>-1</repeat-count>
        <repeat-interval>3000</repeat-interval>
      </simple>
    </trigger>

  </schedule>

</job-scheduling-data>

You can also make the XML to auto refresh the store on change (checked every 10 seconds) if you define:

properties["quartz.plugin.xml.ScanInterval"] = "10";
Yawata answered 6/2, 2014 at 7:13 Comment(2)
Near perfect! (Thanks). I had to call IScheduler.Start() for the values to persist to the database.....I edited my answer with my complete code base.Angkor
Thanks. Agile-Task complete!Angkor

© 2022 - 2024 — McMap. All rights reserved.