dba/jobs  library module
PR

Summary

Downloads a job result.
Tags

Author: Christian Grün, BaseX Team 2005-21, BSD License

__source : jobs/job-result.xqm

Related documents
ViewDescriptionFormat
xqdocxqDoc xml file from the source modulexml
xqparsexqparse xml file from the source modulexml

Imports

This module is imported by 0 modules. It imports 0 modules.

Variables

3.1 $dba:CAT

Summary
Top category
Type
xs:string

Functions

4.1 dba:job-result

Arities: dba:job-result#1Rdba:job-result#3P

Summary
Downloads the result of a job.
Signature
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()+
Parameters
  • id as xs:string job id
Return
  • 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:

PrefixUri
annhttp://www.w3.org/2012/xquery
dbadba/jobs 2 3
resthttp://exquery.org/ns/restxq

6 RestXQ

Paths defined 1.

PathMethodFunction
/dba/job-resultGETdba:job-result#1

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
};