92 lines
3.5 KiB
Plaintext
92 lines
3.5 KiB
Plaintext
(:~
|
|
: Report library.
|
|
:
|
|
: @author Rave Technologies, https://www.rave-tech.com/, 2017
|
|
:)
|
|
|
|
module namespace rpsrv = 'http://www.rave-tech.com/bloomsbury/report-psrv';
|
|
import module namespace cpsrv = 'http://www.rave-tech.com/bloomsbury/config-psrv' at 'config-psrv.xqm';
|
|
import module namespace copsrv = 'http://www.rave-tech.com/bloomsbury/contents-psrv' at 'content-psrv.xqm';
|
|
declare namespace pipeline = 'http://cms.bloomsbury.com/pipeline';
|
|
|
|
(:~
|
|
: Append error report to the specific job.
|
|
: @param $jobID ID of the job to update status
|
|
: @param $stepReport The step information to record
|
|
: @return empty sequence
|
|
:)
|
|
declare %updating function rpsrv:update(
|
|
$jobID as xs:string,
|
|
$stepReport as element(step)
|
|
)
|
|
{
|
|
file:append(fn:concat($cpsrv:TempPipelineDir,$jobID,$cpsrv:ReadyToMove,$cpsrv:JobDir,$jobID,'.xml'),$stepReport)
|
|
};
|
|
|
|
|
|
(:~
|
|
: Append final status of the report.
|
|
: @param $jobID ID of the job to update status
|
|
: @param $ignoreValidation Ignore validation if error happens
|
|
: @param $contentID ID of the content
|
|
: @return empty sequence
|
|
:)
|
|
declare %updating function rpsrv:update-final-status(
|
|
$jobID as xs:string,
|
|
$ignoreValidation as xs:string,
|
|
$contentID as xs:string
|
|
)
|
|
{
|
|
let $reportUri := fn:concat($cpsrv:TempPipelineDir,$jobID,$cpsrv:ReadyToMove,$cpsrv:JobDir,$jobID,'.xml')
|
|
let $file := file:read-text($reportUri)
|
|
let $steps := fn:substring-after($file,'</job>')
|
|
let $jobText := fn:parse-xml(fn:substring-before($file,$steps))
|
|
let $jobXml := copy $c := $jobText
|
|
modify replace node $c/job/ingestion-report/steps with fn:parse-xml(fn:concat('<steps>',fn:normalize-space($steps),'</steps>'))
|
|
return $c
|
|
return
|
|
if($jobXml/job/ingestion-report/status[.='InProgress'] or $jobXml/job/ingestion-report/status[.=''])
|
|
then
|
|
(
|
|
if($jobXml/job/ingestion-report/steps/step/error/*)
|
|
then
|
|
if($ignoreValidation='true')
|
|
then
|
|
let $jobXml := copy $c := $jobXml
|
|
modify
|
|
(
|
|
replace node $c/job/ingestion-report/status with <status>SuccessWithWarnings</status>,
|
|
replace node $c/job/ingestion-report/finished-on with <finished-on>{fn:adjust-dateTime-to-timezone(convert:integer-to-dateTime(prof:current-ms()))}</finished-on>
|
|
)
|
|
return $c
|
|
return file:write($reportUri,$jobXml)
|
|
else
|
|
(
|
|
let $jobXml := copy $c := $jobXml
|
|
modify
|
|
(
|
|
replace node $c/job/ingestion-report/status with <status>Failure</status>,
|
|
replace node $c/job/ingestion-report/finished-on with <finished-on>{fn:adjust-dateTime-to-timezone(convert:integer-to-dateTime(prof:current-ms()))}</finished-on>,
|
|
for $d in $c/job/job-info/lock/file
|
|
return
|
|
replace node $d/latest-version with <latest-version>{$d/previous-version/string()}</latest-version>
|
|
)
|
|
return $c
|
|
return file:write($reportUri,$jobXml)
|
|
,
|
|
file:delete(fn:concat($cpsrv:TempPipelineDir,$jobID,$cpsrv:ReadyToMove,$cpsrv:ContentDir),fn:true())
|
|
)
|
|
else
|
|
let $jobXml := copy $c := $jobXml
|
|
modify
|
|
(
|
|
replace node $c/job/ingestion-report/status with <status>Success</status>,
|
|
replace node $c/job/ingestion-report/finished-on with <finished-on>{fn:adjust-dateTime-to-timezone(convert:integer-to-dateTime(prof:current-ms()))}</finished-on>
|
|
)
|
|
return $c
|
|
return file:write($reportUri,$jobXml)
|
|
)
|
|
else ()
|
|
};
|
|
|