2017-09-04 25 views
3

こんにちは私は摂取と検証を行っていますが、取り込みと検証の開始時間と終了時間を記録したいと思います。私のコードは以下の通りです。タスク開始時間とタスク終了時間をBaseXに記録する方法

let $pipelineXml := 
<pipeline id='a111' name='ACH-export' xmlns='http://cms.bloomsbury.com/pipeline'> 
    <transform href='/transforms/docbook2xml.xsl'/> 
    <validate href='/validation/taxonomy.sch' failOnError='true'/> 
</pipeline> 
let $reportChunk := <report> 
          <info> 
           <id>{$pipelineXml//@id}</id> 
           <name>{$pipelineXml//@name}</name> 
           <submitted-on>{fn:current-dateTime()}</submitted-on> 
           <user>{user:current()}</user> 
          </info> 
          <ingestion-report> 
           <steps/> 
          </ingestion-report> 
         </report> 
let $startTime := fn:current-dateTime() 
let $validate := validate:rng-report($pipelineXml, bin:decode-string(db:retrieve($config:Database, fn:concat($config:ValidationDir,$config:PipelineRelaxNG)),'UTF-8'), fn:true()) 
return 
if($validate/status='valid') 
     then 
    (

     admin:write-log("[" || "][Pipeline is valid as per Relax NG : " || $pipelineXml//@id || "]") 
      , 
      let $appendReport := let $updateReport := <step> 
                  <type>RELAX NG Validation</type> 
                  <started-on>{$startTime,prof:sleep(20000)}</started-on> 
                  <completed-on>{fn:current-dateTime()}</completed-on> 
                  <status>Pass</status> 
                  <error></error> 
                 </step> 
            return 
            copy $target := $reportChunk 
            modify insert node $updateReport as last into $target/ingestion-report/steps 
            return $target 


        return $appendReport 
    ) 
    else "error" 

答えて

3

こんにちはダーメンドラクマール・シン、

current-Time()機能はに変換、いわゆる決定的関数です:

[定義]を生成することが保証されて機能・同じ・ 単一の実行スコープ内で繰り返し呼び出された結果• 明示的および暗黙的な引数が同一である場合は、確定的に と呼ばれます。 https://www.w3.org/TR/xpath-functions-3/#dt-deterministic

言われていること:あなたのstartTimeendTimeは同じです。

それでも、あなたはあなたの実際のニーズに応じて、いくつかの可能性、持っている:

  1. あなたがタイムスタンプを取得し、あなたの時間を計算し、その値を使用する(非決定的関数である)prof:current-nsを使用することができます:

http://docs.basex.org/wiki/Profiling_Module#prof:current-ns

let $ns1 := prof:current-ns() 
return (
    (: process to measure :) 
    (1 to 1000000)[. = 0], 
    let $ns2 := prof:current-ns() 
    let $ms := ((($ns2 - $ns1) idiv 10000) div 100) 
    return $ms || ' ms' 
) 

それとも、使用することができ、内蔵タイミング機能実行に必要な時間を記録します:

http://docs.basex.org/wiki/Profiling_Module#prof:time

あなたが何か書くことができ

Profiling result in the GUI


追記:次のような結果が得られ

let $rng := <element name="addressBook" xmlns="http://relaxng.org/ns/structure/1.0"> 
    <zeroOrMore> 
    <element name="card"> 
     <element name="name"> 
     <text/> 
     </element> 
     <element name="email"> 
     <text/> 
     </element> 
    </element> 
    </zeroOrMore> 
</element> 

let $doc := <addressBook>{ 
for $i in 1 to 1000 
    return <cards> 
    <name>John Smith</name> 
    <email>[email protected]</email> 
    </cards> 
} 
</addressBook> 


let $report  := prof:time(validate:rng-report($doc, $rng), true(), 'RNG Validation ') 
let $report-size := prof:time(count($report//*) , true(), 'Counting ') 
return $report 

を:何ですか? bin:decode-string(db:retrieve…)のために? これをdb:open('…path-to-file…')に置き換えて、Relax-NGスキーマをバイナリではなくXMLファイルとして保存することができます。 17::お返事マイケルが、私の要件については

+0

おかげでフォーマットで時間を格納する2017-09-04T17である14.989 + 05:30 <完成オン> 2017-09-04T17:17:14.989 + 05:あなたはこれを大いに助けてくれるならば、私は現在のコードでこれを実装することができます –

+1

私はガイドのためのソリューション感謝を得ましたMichael:私はfn:current-date-timeをreplaceと置き換えました。 -dateTime-to-timezone(変換:integer-to-dateTime(prof:current-ms())) –

+0

素晴らしい:-)有用であれば、私の答えを受け入れることを検討するかもしれないhttps://meta.stackexchange.com/questions/5234 /答えを受け入れる方法 – michael

関連する問題