dba/jobs  library module
RP

Summary

Downloads a job result.
Authors
  • Christian Grün, BaseX Team 2005-23, BSD License
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
Type
Source ( 1 lines)
variable $dba:CAT := 'jobs'

Functions

4.1 dba:job-result

Arities: #1R#3P

Summary
Downloads the result of a job.
Signatures
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
  • ok as xs:boolean ok flag
  • result as item()* job result
Return
  • item() + rest response and file content
Invoked by 0 functions from 0 modules
    Annotations (3)
    %rest:GET()
    %rest:path('/dba/job-result')
    %rest:query-param('id','{$id}','')
    Annotations (1)
    %private()
    Source ( 31 lines)
    function dba:job-result(
      $id  as xs:string
    ) as item()+ {
      let $details := job:list-details($id)
      return if(empty($details)) then (
        dba:job-result($id, false(), 'Job has expired.')
      ) else if($details/@state != 'cached') then (
        dba:job-result($id, false(), 'Result is not available yet.')
      ) else (
        try {
          dba:job-result($id, true(), job:result($id))
        } catch * {
          dba:job-result($id, false(),
            'Stopped at ' || $err:module || ', ' || $err:line-number || '/' ||
              $err:column-number || ':' || string: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
    dbadba/jobs 2
    errhttp://www.w3.org/2005/xqt-errors
    resthttp://exquery.org/ns/restxq
    webhttp://basex.org/modules/web
    xshttp://www.w3.org/2001/XMLSchema

    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-23, 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 := job:list-details($id)
      return if(empty($details)) then (
        dba:job-result($id, false(), 'Job has expired.')
      ) else if($details/@state != 'cached') then (
        dba:job-result($id, false(), 'Result is not available yet.')
      ) else (
        try {
          dba:job-result($id, true(), job:result($id))
        } catch * {
          dba:job-result($id, false(),
            'Stopped at ' || $err:module || ', ' || $err:line-number || '/' ||
              $err:column-number || ':' || string: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
    };