我有一個可以從查詢控制檯(QC)運行的XQuery。 我在任務服務器上有一個任務設置。查詢從任務服務器運行找不到文件?
該查詢似乎無法找到搜索的文件,所以這必須是權限問題是我的猜測。
任務查詢:
xquery version "1.0-ml";
import module namespace object = "http://marklogic.com/solutions/obi/object" at
"/ext/obi/lib/object-query-lib.xqy",
"/ext/obi/lib/object-service-lib.xqy",
"/ext/obi/lib/object-lib.xqy";
declare namespace obj="http://marklogic.com/solutions/obi/object";
declare namespace alt="http://example.com/sccs/alert";
declare namespace scc="http://example.com/sccs";
declare namespace source="http://marklogic.com/solutions/obi/source";
(: Start task :)
let $_ := xdmp:log("******* START CHECK UPDATE ALERTS TASK *********")
(: Find al active alerts :)
let $alerts := cts:search(
collection("object"),
cts:and-query((
cts:element-range-query(xs:QName("obj:type"), "=", "alert"),
cts:element-range-query(xs:QName("alt:status"), "=", "Active")
(:
cts:element-range-query(xs:QName("alt:device-id"), "=", $device-id)
:)
))
)/obj:object
let $update-object-content := <alert xmlns="http://example.com/sccs/alert">
<obj:property>
<status xmlns="http://example.com/sccs/alert">Inactive</status>
</obj:property>
</alert>
let $now := fn:current-dateTime()
(: minimum duration before alerts turns inactive :)
let $duration-min := xs:dayTimeDuration('PT25M0S') (: defines 30 minutes :)
(: loop over all active alerts :)
let $_ :=
for $a in $alerts
let $a-id := $a//obj:id/text()
let $s-id := $a//source:id/text()[1]
let $timestamp := xdmp:parse-dateTime('[Y0001]-[M01]-[D01]T[h01]:[m01]:[s01]',$a//scc:timestamp/text())
(: if Alert is older then $delta then set status to Inactive :)
let $delta := $now - $timestamp
let $upd := if ($delta > $duration-min) then
(
let $_ := xdmp:log(fn:concat("Update Alert ID : ",$a-id," to INACTIVE."))
let $detail-id := obj:add-details($a-id, $update-object-content, $s-id,())
return $detail-id
)
else()
return $upd
let $_ := xdmp:log(fn:concat("DEBUG NUM ALERTS:",fn:count($alerts)))
return()
任務defenition:
<scheduled-task>
<task-path>/tasks/update-alerts-to-inactive.xqy</task-path>
<task-root>/</task-root>
<task-type>minutely</task-type>
<task-period>5</task-period>
<task-database name="${content-db}"/>
<task-modules name="${app-modules-db}"/>
<task-user name="${app-name}-user"/>
</scheduled-task>
任務檢查每5分鐘,如果警報對象需要被設置爲 「無效」。
從日誌Error.txt我可以看到任務運行但找不到文檔。
2015-10-26 00:45:00.395 Info: TaskServer: ******* START CHECK UPDATE ALERTS TASK *********
2015-10-26 00:45:00.395 Info: TaskServer: DEBUG NUM ALERTS:0
我運行codepoint根歸類中的所有代碼,但在此上下文中找不到任何與taskserver相關的任何代碼。
的documentation on permissions needed for the user to perform a task非常cryptical:
在任務用戶和任務主機字段中,指定用戶與 權限調用任務,並在其上的任務 是要調用的主機。如果未指定主機,則該任務將在所有主機上運行 。在「任務用戶」字段中指定的用戶必須具有執行模塊中使用的功能所需的 權限。請參閱 附錄B:預定義執行權限 的完整列表執行特權。
問題:爲什麼不能在任務服務器上查找文檔?
UPDATE
試圖獲取OBI文檔的權限但失敗。
這是代碼(由Dave的建議)
import module namespace sec="http://marklogic.com/xdmp/security" at
"/MarkLogic/security.xqy";
declare namespace obj="http://marklogic.com/solutions/obi/object";
let $o-id := cts:search(
collection("object"),
cts:and-query((
cts:element-range-query(xs:QName("obj:type"), "=", "alert")
))
)/obj:object/obj:id/text()
let $uri := object:master-uri($o-id)
let $res := for $perm in xdmp:document-get-permissions($uri)
let $role-name := sec:get-role-names($perm/sec:role-id)
return $role-name || ": " || $perm/sec:capability/fn:string()
let $string-uri := '/marklogic.solutions.obi/object/cec48c59-a648-4da5-a758-2b6bb4065279.xml'
return xdmp:document-get-permissions($string-uri)
我運行此作爲對QC管理,它返回空序列...
只是,嘗試僅在另一個QC查詢中運行$ alerts變量內容。你能找出任何結果嗎?請檢查您選擇的數據庫,選擇那些包含您正在搜索的文檔的數據庫。 –