BaseX中如何记录任务开始时间和任务结束时间
How to record task start time and task end time in 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"
嗨,Dharmendra Kumar Singh,
current-Time()
函数是所谓的确定性函数,转换为:
[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
也就是说:您的 startTime
和 endTime
是相同的。
不过,你有几种可能,取决于你的实际需要:
- 您可以使用
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'
)
或者您可以使用内置计时功能 prof:time
记录执行所需的时间:
http://docs.basex.org/wiki/Profiling_Module#prof:time
你可以这样写:
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>js@example.com</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 文件而不是二进制文件?
你好,我正在进行摄取和验证,但我想记录摄取和验证的开始时间和结束时间。以下是我的代码我做错了什么请提出建议。
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"
嗨,Dharmendra Kumar Singh,
current-Time()
函数是所谓的确定性函数,转换为:
[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
也就是说:您的 startTime
和 endTime
是相同的。
不过,你有几种可能,取决于你的实际需要:
- 您可以使用
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'
)
或者您可以使用内置计时功能 prof:time
记录执行所需的时间:
http://docs.basex.org/wiki/Profiling_Module#prof:time
你可以这样写:
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>js@example.com</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 文件而不是二进制文件?