xdmp:log 使用 CPF (MarkLogic) 时出错
xdmp:log Error while using CPF (MarkLogic)
我试图按照 Marklogic 上的教程创建我们自己的 CPF。我几乎复制并粘贴了所有代码,除了 xdmp:log 之外,大多数功能都可以使用。 CPF 将在达到它时结束它的任务。 marklogic 的文档可以在这里找到 Getting Started with a Simple CPF Application
如果我做错了什么,我会post我的代码和我所做的。
=======使用的文档=======
add-last-updated.xqy => 添加到模块 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 => 添加到模块 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 => 添加到管道并附加到 "Default Documents" 域
<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" 日志中。我的一个愚蠢的问题,感谢您的帮助。
你格式化代码的方式向我建议你认为 xdmp:log
和 cpf:success
行属于 return
,但事实并非如此:只有第一个表达式在 return
之后。因此,当您重新排序这些行时,您可能会在此模块上遇到未定义的变量静态错误。您实际上并不需要 let
和 return
:您可以直接在 xdmp:node-replace
调用中使用 doc($document-uri)/book
。然后你可以随意重新排序序列。如果您希望 xdmp:node-replace
和 xdmp:log
位于 $doc
变量的范围内,请将该表达式序列用括号括起来。
我试图按照 Marklogic 上的教程创建我们自己的 CPF。我几乎复制并粘贴了所有代码,除了 xdmp:log 之外,大多数功能都可以使用。 CPF 将在达到它时结束它的任务。 marklogic 的文档可以在这里找到 Getting Started with a Simple CPF Application
如果我做错了什么,我会post我的代码和我所做的。
=======使用的文档=======
add-last-updated.xqy => 添加到模块 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 => 添加到模块 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 => 添加到管道并附加到 "Default Documents" 域
<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" 日志中。我的一个愚蠢的问题,感谢您的帮助。
你格式化代码的方式向我建议你认为 xdmp:log
和 cpf:success
行属于 return
,但事实并非如此:只有第一个表达式在 return
之后。因此,当您重新排序这些行时,您可能会在此模块上遇到未定义的变量静态错误。您实际上并不需要 let
和 return
:您可以直接在 xdmp:node-replace
调用中使用 doc($document-uri)/book
。然后你可以随意重新排序序列。如果您希望 xdmp:node-replace
和 xdmp:log
位于 $doc
变量的范围内,请将该表达式序列用括号括起来。