psvr/sch-psrv.xqm

34 lines
1.6 KiB
Plaintext

(:~
: Execute jobs
:
: @author Rave Technologies, https://www.rave-tech.com/, 2017
:)
import module namespace cpsrv = 'http://www.rave-tech.com/bloomsbury/config-psrv' at 'config-psrv.xqm';
import module namespace jpsrv = 'http://www.rave-tech.com/bloomsbury/jobs-psrv' at 'jobs-psrv.xqm';
let $httpTarget := admin:write-log('--------job invoke --------')
let $httpTarget := fn:concat(fn:substring-before($cpsrv:DataServer,'/rest/'),'/data/jobs')
let $file := fn:string(convert:dateTime-to-integer(fn:adjust-dateTime-to-timezone(convert:integer-to-dateTime(prof:current-ms()))))
let $job := (http:send-request(<http:request method='get' username='admin' password='admin' send-authorization='true'
href='{$httpTarget}' auth-method='Basic'>
</http:request>)
)[2]
return
if($job/job[.='NONE'])
then admin:write-log('============= No job to process ==================')
else
(
let $jobID := $job/job/job-info/id/text()
let $httpTarget := fn:concat(fn:substring-before($cpsrv:DataServer,'/rest/'),'/data/job/update')
let $file := fn:string(convert:dateTime-to-integer(fn:adjust-dateTime-to-timezone(convert:integer-to-dateTime(prof:current-ms()))))
let $jobUpdate := (http:send-request(<http:request method='post' username='admin' password='admin' send-authorization='true'
href='{$httpTarget}' auth-method='Basic'>
<http:header name="Content-Type" value="application/xml"/>
<http:body media-type='application/xml'>
<job>{$jobID}</job>
</http:body>
</http:request>)
)
return jpsrv:run-job($job)
)