How to record task start time and task end time in BaseX

163 Views Asked by At

hi i am doing the ingestion and validation but i want to record the start time and end time of the ingestion and validation. below are my code what i am doing wrong please suggest.

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"
1

There are 1 best solutions below

3
On BEST ANSWER

Hi Dharmendra Kumar Singh,

the current-Time() function is a so called deterministic function, which translates to:

[Definition] A function that is guaranteed to produce ·identical· results from repeated calls within a single ·execution scope· if the explicit and implicit arguments are identical is referred to as deterministic. https://www.w3.org/TR/xpath-functions-3/#dt-deterministic

That being said: your startTime and endTime are identical.

Still, you have several possibilities, depending on your actual needs:

  1. you can use prof:current-ns (which is a non-deterministic function) to get a timestamp and use that value to calculate your times:

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'
)

Or you could use the built-in timing function prof:time which logs the time needed for execution:

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

You could write something like:

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

Yielding the following results:

Profiling result in the GUI


Sidenote: whats the bin:decode-string(db:retrieve…) part for? You might want to replace that with a db:open('…path-to-file…') and store your Relax-NG schema as an XML file instead of a binary?