2017-09-04 7 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' 
) 

또는 당신이 사용할 수있는 내장 된 타이밍 기능실행을 위해 필요한 시간을 기록 9,:

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 : 30 현재까지 코드에서 구현할 수있는 방법은 무엇입니까? –

+1

가이드 용 솔루션 덕분에 Michael : 저는 fn : current-date-time을 replace로 대체했습니다. -dateTime-to-timezone (변환 : integer-to-dateTime (prof : current-ms())) –

+0

위대한 :-) 도움이 되었다면 내 대답을 수락하는 것을 고려해보십시오. https://meta.stackexchange.com/questions/5234/대답하는 법안 – michael