dba/jobs
library modulePR
Summary
Downloads a job result.
- Tags
Author: Christian Grün, BaseX Team 2005-21, BSD License
__source : jobs/job-result.xqm
Imports
This module is imported by 0 modules. It imports 0 modules.
Variables
Functions
4.1 dba:job-result
Arities: dba:job-result#1Rdba:job-result#3P
dba:job-result
(
$id
as
xs:string
)
as
item() +
dba:job-result
(
$id
as
xs:string
, $ok
as
xs:boolean
, $result
as
item()*
)
as
item() +
- id
as
xs:string
job id
item() +
rest response and file content
Invokes 8 functions from 5 modules
- dba:job-result#3
- {http://basex.org/modules/jobs}list-details#1
- {http://basex.org/modules/jobs}result#1
- {http://basex.org/modules/out}nl#0
- {http://basex.org/modules/web}response-header#2
- {http://www.w3.org/2005/xpath-functions}empty#1
- {http://www.w3.org/2005/xpath-functions}false#0
- {http://www.w3.org/2005/xpath-functions}true#0
Invoked by 1 functions from 1 modules
Annotations
%rest:GET | () |
%rest:path | ('/dba/job-result') |
%rest:query-param | ('id','{$id}','') |
Annotations
%private | () |
Source ( 31 lines)
function dba:job-result(
$id as xs:string
) as item()+ {
let $details := jobs:list-details($id)
return if(empty($details)) then (
dba:job-result($id, false(), 'Job is defunct.')
) else if($details/@state != 'cached') then (
dba:job-result($id, false(), 'Result is not available yet.')
) else (
try {
dba:job-result($id, true(), jobs:result($id))
} catch * {
dba:job-result($id, false(),
'Stopped at ' || $err:module || ', ' || $err:line-number || '/' ||
$err:column-number || ':' || out:nl() || $err:description
)
}
)
}
function dba:job-result(
$id as xs:string,
$ok as xs:boolean,
$result as item()*
) as item()+ {
let $name := $id || (if($ok) then '.txt' else '.log')
return web:response-header(
map { 'media-type': 'application/octet-stream' },
map { 'Content-Disposition': 'attachment; filename=' || $name }
),
$result
}
Namespaces
The following namespaces are defined:
Prefix | Uri |
---|---|
ann | http://www.w3.org/2012/xquery |
dba | dba/jobs 2 3 |
rest | http://exquery.org/ns/restxq |
Source Code
(:~
: Downloads a job result.
:
: @author Christian Grün, BaseX Team 2005-21, BSD License
:)
module namespace dba = 'dba/jobs';
(:~ Top category :)
declare variable $dba:CAT := 'jobs';
(:~
: Downloads the result of a job.
: @param $id job id
: @return rest response and file content
:)
declare
%rest:GET
%rest:path('/dba/job-result')
%rest:query-param('id', '{$id}', '')
function dba:job-result(
$id as xs:string
) as item()+ {
let $details := jobs:list-details($id)
return if(empty($details)) then (
dba:job-result($id, false(), 'Job is defunct.')
) else if($details/@state != 'cached') then (
dba:job-result($id, false(), 'Result is not available yet.')
) else (
try {
dba:job-result($id, true(), jobs:result($id))
} catch * {
dba:job-result($id, false(),
'Stopped at ' || $err:module || ', ' || $err:line-number || '/' ||
$err:column-number || ':' || out:nl() || $err:description
)
}
)
};
(:~
: Returns a job result.
: @param $id job id
: @param $ok ok flag
: @param $result job result
: @return rest response and file content
:)
declare %private function dba:job-result(
$id as xs:string,
$ok as xs:boolean,
$result as item()*
) as item()+ {
let $name := $id || (if($ok) then '.txt' else '.log')
return web:response-header(
map { 'media-type': 'application/octet-stream' },
map { 'Content-Disposition': 'attachment; filename=' || $name }
),
$result
};