通过 xml 配置的 context.Trigger.JobDataMap 值 [英] context.Trigger.JobDataMap values via xml configuration

查看:28
本文介绍了通过 xml 配置的 context.Trigger.JobDataMap 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在quartz_jobs.xml中,我可以为job设置一些参数.....

In quartz_jobs.xml, I can set some parameters for the job.....

   <job>
        <name>MyJob</name>
        <group>MyJob</group>
        <description>My Job</description>
        <job-type>MyAssembly.MyJob, MyAssembly</job-type>
        <durable>true</durable>
        <recover>false</recover>
        <job-data-map>
            <entry>
                <key>JobMapDataKeyOne</key>
                <value>JobMapDataValueOne</value>
            </entry>
            <entry>
                <key>JobMapDataKeyTwo</key>
                <value>JobMapDataValueTwo</value>
            </entry>
        </job-data-map>

    </job>

这是代码:

public class MyJob: IJob
{

    public virtual void Execute(IJobExecutionContext context)
    {

        JobKey key = context.JobDetail.Key;

        JobDataMap jbDataMap = context.JobDetail.JobDataMap;

        string jobMapDataValueOne = jbDataMap.GetString("JobMapDataKeyOne");
        string jobMapDataValueTwo = jbDataMap.GetString("JobMapDataKeyOne");

    }
}

现在,我可以编写作业并触发"(不使用 .xml 设置)(未看到代码)......我可以让下面的工作正常工作.(并为 triggerParameter001Value 和 triggerParameter002Value 填充了值).

Now, I can "code up a job and trigger" (not using .xml setup) (code not seen).... and I can get the below to work. (And have populated values for triggerParameter001Value and triggerParameter002Value ).

public class MyJob: IJob
{

    public virtual void Execute(IJobExecutionContext context)
    {

        JobKey key = context.JobDetail.Key;

        JobDataMap trgDataMap = context.Trigger.JobDataMap;

        string triggerParameter001Value = trgDataMap.GetString("TriggerParameter001Key");
        string triggerParameter002Value = trgDataMap.GetString("TriggerParameter002Key");

    }
}

但我没有看到为触发器传递参数的方法...在 xml 中定义.

But I don't see a way to pass parameters for the Trigger...defined in the xml.

我搜索过

"trigger-data-map"

"jobtrigger-data-map"

无济于事.

我也在http://quartznet.sourceforge.net/JobSchedulingData"xsd 附近钓鱼.这只是在xml中缺少吗?我错过了什么吗?

I fished around the "http://quartznet.sourceforge.net/JobSchedulingData" xsd as well. Is this just missing in the xml? Am I missing something?

推荐答案

好的.这个是SNEAKY!

Ok. This one was SNEAKY!

以下不起作用:(注意job-data-map"元素的位置~在simple"元素下)

The below will NOT work: (note the position of "job-data-map" element ~under the "simple" element)

   <job>
        <name>MyJob</name>
        <group>MyJobGroup</group>
        <description>My Job</description>
        <job-type>MyAssembly.MyJob, MyAssembly</job-type>
        <durable>true</durable>
        <recover>false</recover>
        <job-data-map>
            <entry>
                <key>JobMapDataKeyOne</key>
                <value>JobMapDataValueOne</value>
            </entry>
            <entry>
                <key>JobMapDataKeyTwo</key>
                <value>JobMapDataValueTwo</value>
            </entry>
        </job-data-map>


    </job>

        <trigger>

            <simple>
                <name>MyTrigger</name>
                <group>MyTriggerJobGroup</group>
                <description>MyTriggerDescription</description>
                <job-name>MyJob</job-name>
                <job-group>MyJobGroup</job-group>


                <!--<start-time>1982-06-28T18:15:00.0Z</start-time>-->
                <!--<end-time>2020-05-04T18:13:51.0Z</end-time>-->
                <misfire-instruction>SmartPolicy</misfire-instruction>
                <!-- repeat indefinitely every 10 seconds -->
                <repeat-count>-1</repeat-count>
                <repeat-interval>5000</repeat-interval>


                <job-data-map>
                    <entry>
                        <key>TriggerParameter001Key</key>
                        <value>TriggerParameter001Value</value>
                    </entry>
                    <entry>
                        <key>TriggerParameter002Key</key>
                        <value>TriggerParameter002Value</value>
                    </entry>

                </job-data-map>


            </simple>

        </trigger>

上面的 xml 给了我这样的错误:

The above xml was giving me an error like this:

Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin.ProcessFile 错误调度作业错误:命名空间http://quartznet.sourceforge.net/JobSchedulingData' 在命名空间 'http://quartznet.sourceforge.net/JobSchedulingData'.

Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin.ProcessFile Error Error scheduling jobs: The element 'simple' in namespace 'http://quartznet.sourceforge.net/JobSchedulingData' has invalid child element 'job-data-map' in namespace 'http://quartznet.sourceforge.net/JobSchedulingData'.

………………

以下将起作用(注意job-data-map"的位置变化(仍在simple"元素下,但向上"移动了一些)

The below WILL work (note the position change of "job-data-map" (still under "simple" element, but moved "up" some)

   <job>
        <name>MyJob</name>
        <group>MyJobGroup</group>
        <description>My Job</description>
        <job-type>MyAssembly.MyJob, MyAssembly</job-type>
        <durable>true</durable>
        <recover>false</recover>
        <job-data-map>
            <entry>
                <key>JobMapDataKeyOne</key>
                <value>JobMapDataValueOne</value>
            </entry>
            <entry>
                <key>JobMapDataKeyTwo</key>
                <value>JobMapDataValueTwo</value>
            </entry>
        </job-data-map>


    </job>

        <trigger>

            <simple>
                <name>MyTrigger</name>
                <group>MyTriggerJobGroup</group>
                <description>MyTriggerDescription</description>
                <job-name>MyJob</job-name>
                <job-group>MyJobGroup</job-group>


                <job-data-map>
                    <entry>
                        <key>TriggerParameter001Key</key>
                        <value>TriggerParameter001Value</value>
                    </entry>
                    <entry>
                        <key>TriggerParameter002Key</key>
                        <value>TriggerParameter002Value</value>
                    </entry>

                </job-data-map>



                <!--<start-time>1982-06-28T18:15:00.0Z</start-time>-->
                <!--<end-time>2020-05-04T18:13:51.0Z</end-time>-->
                <misfire-instruction>SmartPolicy</misfire-instruction>
                <!-- repeat indefinitely every 10 seconds -->
                <repeat-count>-1</repeat-count>
                <repeat-interval>5000</repeat-interval>



            </simple>

        </trigger>

为什么?

xsd 使用抽象类型

  <xs:complexType name="abstractTriggerType" abstract="true">
    <xs:annotation>
      <xs:documentation>Common Trigger definitions</xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="name" type="xs:string" />
      <xs:element name="group" type="xs:string" minOccurs="0" />
      <xs:element name="description" type="xs:string" minOccurs="0" />
      <xs:element name="job-name" type="xs:string" />
      <xs:element name="job-group" type="xs:string" minOccurs="0" />
      <xs:element name="priority" type="xs:nonNegativeInteger" minOccurs="0" />
      <xs:element name="calendar-name" type="xs:string" minOccurs="0" />
      <xs:element name="job-data-map" type="job-data-mapType" minOccurs="0" />



  <xs:complexType name="simpleTriggerType">
    <xs:annotation>
      <xs:documentation>Define a SimpleTrigger</xs:documentation>
    </xs:annotation>
    <xs:complexContent>
      <xs:extension base="abstractTriggerType">
        <xs:sequence>
          <xs:element name="misfire-instruction" type="simple-trigger-misfire-instructionType" minOccurs="0" />
          <xs:sequence minOccurs="0">
            <xs:element name="repeat-count" type="repeat-countType" />
            <xs:element name="repeat-interval" type="xs:nonNegativeInteger" />
          </xs:sequence>

所以作为抽象的一部分的所有东西都必须在~任何具体属性之前定义.

那是偷偷摸摸的!

这篇关于通过 xml 配置的 context.Trigger.JobDataMap 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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