使用CPF(MarkLogic)时xdmp:log错误

时间:2019-02-22 09:12:14

标签: alert marklogic

我试图遵循有关Marklogic的教程来创建我们自己的CPF。我几乎复制并粘贴了所有代码,并且除了xdmp:log之外,大多数功能都起作用。 CPF将在达成目标时结束其任务。您可以在Getting Started with a Simple CPF Application

中找到marklogic的文档。

万一我做错了什么,我会在这里和我的代码中贴上我的代码。

========使用的文档=======

add-last-updated.xqy =>已添加到Modules DB

xquery version "1.0-ml";
import module namespace cpf="http://marklogic.com/cpf" 
  at "/MarkLogic/cpf/cpf.xqy";
declare variable $cpf:document-uri as xs:string external;
declare variable $cpf:transition as node() external;
if (cpf:check-transition($cpf:document-uri,$cpf:transition)) then try {
  let $doc := fn:doc($cpf:document-uri)
  return
      xdmp:node-insert-child(
        $doc/book,
        <last-updated>{fn:current-dateTime()}</last-updated>
      ),
  xdmp:log( "add last-updated ran OK" ),
  cpf:success($cpf:document-uri, $cpf:transition, ())
} catch ($e) {
  cpf:failure($cpf:document-uri, $cpf:transition, $e, ())
}
else ()

add-copyright.xqy =>已添加到Modules DB

xquery version "1.0-ml";
import module namespace cpf = "http://marklogic.com/cpf" 
  at "/MarkLogic/cpf/cpf.xqy";
declare variable $cpf:document-uri as xs:string external;
declare variable $cpf:transition as node() external;
if (cpf:check-transition($cpf:document-uri,$cpf:transition)) then try {
  let $doc := fn:doc( $cpf:document-uri )
  return
      xdmp:node-insert-child( 
        $doc/book,
        <copyright>
          <year>2010</year>
          <holder>The Publisher</holder>
        </copyright>),
      xdmp:log( "add copyright ran OK" ),
      cpf:success( $cpf:document-uri, $cpf:transition, () )
}
catch ($e) {
  cpf:failure( $cpf:document-uri, $cpf:transition, $e, () )
}
else ()

copyright.xml =>已添加到管道并附加到“默认文档”域

<pipeline xmlns="http://marklogic.com/cpf/pipelines">
  <pipeline-name>Copyright Pipeline</pipeline-name>
  <pipeline-description>Pipeline to test CPF</pipeline-description>
  <success-action>
    <module>/MarkLogic/cpf/actions/success-action.xqy</module>
  </success-action>
  <failure-action>
    <module>/MarkLogic/cpf/actions/failure-action.xqy</module>
  </failure-action>
  <state-transition>
    <annotation>
      When a document containing ‘book' as a root element is created, 
      add a ‘copyright' statement.
    </annotation>
    <state>http://marklogic.com/states/initial</state>
    <on-success>http://marklogic.com/states/done</on-success>
    <on-failure>http://marklogic.com/states/error</on-failure>
    <execute>
      <condition>
        <module>/MarkLogic/cpf/actions/namespace-condition.xqy</module>
        <options xmlns="/MarkLogic/cpf/actions/namespace-condition.xqy">
          <root-element>book</root-element>
          <namespace/>
        </options>
      </condition>
      <action>
        <module>add-copyright.xqy</module>
      </action>
    </execute>
  </state-transition>
  <state-transition>
    <annotation>
      When a document containing ‘book' as a root element is updated, 
      add a ‘last-updated' element
    </annotation>
    <state>http://marklogic.com/states/updated</state>
    <on-success>http://marklogic.com/states/done</on-success>
    <on-failure>http://marklogic.com/states/error</on-failure>
    <execute>
      <condition>
        <module>/MarkLogic/cpf/actions/namespace-condition.xqy</module>
        <options xmlns="/MarkLogic/cpf/actions/namespace-condition.xqy">
          <root-element>book</root-element>
          <namespace/>
        </options>
      </condition>
      <action>
        <module>add-last-updated.xqy</module>
      </action>
    </execute>
  </state-transition>
</pipeline>

=======使用======

xquery version "1.0-ml";
let $contents :=   
  <book>
    <bookTitle>All About George</bookTitle>
    <chapter1>
      <chapterTitle>Curious George</chapterTitle>
      <para>
        George Washington crossed the Delaware to see what was on the other side.
      </para>
    </chapter1>
  </book>
return
  xdmp:document-insert("/content.xml", $contents)

通常,代码可以正常工作,并且在第一次插入时会编辑文档以输出,如下所示,但是在MarkLogic / Data / Logs / 8000_ErrorLog中找到的日志未更新。另外,当我尝试将xdmp:log带到xdmp:node-insert-child之上时,CPF会过早停止,并且该节点不会得到编辑。非常感谢您提供帮助解决此问题的建议。

<book>
  <bookTitle>All About George</bookTitle>
  <chapter1>
    <chapterTitle>Curious George</chapterTitle>
    <para>
      George Washington crossed the Delaware to see what was on the other side.
    </para>
  </chapter1>
  <copyright>
    <year>2010</year>
    <holder>The Publisher</holder>
  </copyright>
</book>

=========更新=======

我遵循了mholstege的建议,并删除了我的“ return”和“ let”陈述,并按照grtjn的建议跟踪了日志。从那里我意识到日志被推送到“ TaskServer_Error”日志中。我这是一个愚蠢的问题,感谢您的协助。

1 个答案:

答案 0 :(得分:4)

格式化代码的方式向我暗示,您认为xdmp:logcpf:success行位于return之下,但事实并非如此:只有第一个表达式位于return是。因此,当您对行进行重新排序时,您可能在此模块上收到未定义的变量静态错误。您实际上并不需要letreturn:您可以直接在doc($document-uri)/book调用中使用xdmp:node-replace。然后,您可以随意重新排序序列。如果您希望xdmp:node-replacexdmp:log处于$doc变量的范围内,请在该表达式序列周围加上括号。