Changes

Jump to navigation Jump to search
35 bytes removed ,  13:38, 5 July 2016
no edit summary
Asynchronous query execution is recommendable if a client does not, or cannot, wait until a request is fully processed. This is e. g. the case with web browsers, which will usually cancel a request after a specific timeout. In such cases, you can use asynchronous execution to trigger another server-side process, which will start the time-consuming process, and fetch the result later on as soon as it is available.
==jobs:scheduleeval==
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|jobs:scheduleeval|$query as xs:string|xs:string}}<br />{{Func|jobs:scheduleeval|$query as xs:string, $bindings as map(*)?|xs:string}}<br />{{Func|jobs:scheduleeval|$query as xs:string, $bindings as map(*)?, $options as map(xs:string, xs:string)|xs:string}}<br />
|-
| '''Summary'''
|Schedules the execution evaluation of the supplied {{Code|$query}} and returns a query id. The query will be queued, and the result will optionally be cached. Queries may can be updating. Variables and context items can be declared via {{Code|$bindings}} (see [[XQuery Module#xquery:eval|xquery:eval]] for more details). The {{Code|$options}} parameter contains scheduling options:
* {{Code|cache}}: indicates if the query result will be cached or ignored (default: <code>false</code>):
** The result will be cached in main-memory until it is fetched via [[#jobs:result|jobs:result]], or until {{Option|CACHETIMEOUT}} is exceeded.
* Cache query result. The returned id can be used to pick up the result with [[#jobs:result|jobs:result]]:
<pre class='brush:xquery'>
jobs:scheduleeval("1+3", (), map { 'cache': true() })
</pre>
* A happy birthday mail will be sent at the given date:
<pre class="brush:xquery">
jobs:scheduleeval("import module namespace mail='mail'; mail:send('Happy birthday!')",
(), map { 'start': '2018-09-01T06:00:00' })}}
</pre>
<pre class='brush:xquery'>
declare %rest:POST("{$query}") %rest:path('/start-scheduling') function local:start($query) {
jobs:scheduleeval($query, (), map { 'start': '02:00:00', 'interval': 'P1D' })
};
declare %rest:path('/stop-scheduling/{$id}') function local:stop($id) {
* Query execution is scheduled for every second, and for 10 seconds in total. As the query itself will take 1.5 seconds, it will only be executed every second time:
<pre class="brush:xquery">
jobs:scheduleeval("prof:sleep(1500)", (), map { 'interval': 'PT1S', 'end': 'PT10S' })
</pre>
|}
* The following query demonstrates how the results of an asynchronously executed query can be returned within the same query. Please remember that this is not the common way how these functions will be used in practice:
<pre class='brush:xquery'>
let $query := jobs:scheduleeval('(1 to 10000000)[. = 1]', map{}, map{ 'cache': true() })
return (
hof:until(
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu