RAMJobStore(quartz_jobs.xml)到AdoJobStore数据移动 [英] RAMJobStore (quartz_jobs.xml) to AdoJobStore Data Move

查看:77
本文介绍了RAMJobStore(quartz_jobs.xml)到AdoJobStore数据移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我和我的团队正在尝试找到一种方法,以在安装了Quartz.NET架构的情况下加载"我们的Sql Server数据库.

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"/>

对于演示版,我们一直将作业设置存储在.xml(quartz_jobs.xml)中.

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

我的问题是:

有没有一种方法可以从.xml(quartz_jobs.xml)(Quartz.Simpl.RAMJobStore)中加载"调度数据,然后将其保存"到AdoJobStore(Quartz.Impl.AdoJobStore.JobStoreTX) ?

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) ?

原因是我们的启动"数据可以很容易地写入.xml中.

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

现在,我看到将作业放入AdoJobStore的唯一方法是通过Quartz.Net对象模型用c#代码对它们进行编码".

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.

或回放"一些已配置的TSQL(使用Sql Profiler):(

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

直接问题在(将xml放入sql-server)中" .....更高层次的问题是如何用启动数据填充AdoJobStore ...而不是将其编码"在C#代码中.

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.

我正在输入有效的代码……使用Marko的响应(被接受为答案).

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

我的配置文件:

<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>

我的代码:

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

注意:

我必须调用IScheduler.Start()才能将值保留到数据库中.

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

添加此行的结果:

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

是我可以将条目添加到quartz_job.xml中,并且它将(仅附加)数据库中的数据(在引擎运行时).

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.

推荐答案

您应该能够轻松完成此操作.您可以将XML配置和ADO作业存储结合在一起.这将使XML处理器更新持久性存储中的作业.

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.

这是最低配置:

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();

我们的XML配置包含覆盖指令,以便刷新作业存储:

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>

如果您定义以下内容,还可以使XML在更改时自动刷新商店(每10秒检查一次):

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";

这篇关于RAMJobStore(quartz_jobs.xml)到AdoJobStore数据移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆