【问题标题】:How to record task start time and task end time in BaseXBaseX中如何记录任务开始时间和任务结束时间
【发布时间】:2017-09-04 10:52:27
【问题描述】:

您好,我正在进行摄取和验证,但我想记录摄取和验证的开始时间和结束时间。以下是我的代码我做错了什么请提出建议。

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"

【问题讨论】:

    标签: xquery basex


    【解决方案1】:

    嗨,达门德拉·库马尔·辛格,

    current-Time() 函数是所谓的确定性函数,翻译为:

    [定义] 保证产生·相同·的函数 单个·执行范围·内重复调用的结果,如果 显式和隐式参数相同被称为 确定性的。 https://www.w3.org/TR/xpath-functions-3/#dt-deterministic

    话虽如此:您的startTime 和endTime 是相同的。

    不过,您有多种可能性,具体取决于您的实际需求:

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

    或者您可以使用内置的计时功能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 文件而不是二进制文件?

    【讨论】:

    • 感谢您的回复 Michael 但我的要求是以格式存储时间 2017-09-04T17:17:14.989+05:302017-09-04T17:17:14.989+05:30 仅此而已
    • 我得到了解决方案,感谢指导 Michael:我只用 adjust-dateTime-to-timezone(convert:integer-to-dateTime(prof:current-) 替换了 fn:current-date-time毫秒()))
    • 太棒了 :-) 如果我的回答对您有帮助,您可以考虑接受 meta.stackexchange.com/questions/5234/…
    猜你喜欢
    • 2022-09-30
    • 2014-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-06
    • 2014-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多