A job can be registered as ''service'' by supplying the {{Code|service}} option to {{Function||job:eval}}:
<syntaxhighlight pre lang="'xquery"'>
(: register job as service; will be run every day at 1 am :)
job:eval('db:drop("tmp")', (), map { 'id':'cleanup', 'start':'01:00:00', 'interval':'P1D', 'service': true() }),
|
* Cache query result. The returned ID can be used to pick up the result with {{Function||job:result}}:
<syntaxhighlight pre lang="'xquery"'>
job:eval("1+3", (), map { 'cache': true() })
</syntaxhighlight>
* A happy birthday mail will be sent at the given date:
<syntaxhighlight pre lang="'xquery"'>
job:eval("import module namespace mail='mail'; mail:send('Happy birthday!')",
(), map { 'start': '2018-09-01T06:00:00' })}}
</syntaxhighlight>
* The following [[RESTXQ]] functions can be called to execute a query at 2 am every day. An ID will be returned by the first function, which can be used to stop the scheduler via the second function:
<syntaxhighlight pre lang="'xquery"'>
declare %rest:POST("{$query}") %rest:path('/start-scheduling') function local:start($query) {
job:eval($query, (), map { 'start': '02:00:00', 'interval': 'P1D' })
</syntaxhighlight>
* 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:
<syntaxhighlight pre lang="'xquery"'>
job:eval("prof:sleep(1500)", (), map { 'interval': 'PT1S', 'end': 'PT10S' })
</syntaxhighlight>
* The query in the specified file will be evaluated once:
<syntaxhighlight pre lang="'xquery"'>
job:eval(xs:anyURI('cleanup.xq'))
</syntaxhighlight>
* The following expression, if stored in a file, will be evaluated every 5 seconds:
<syntaxhighlight pre lang="'xquery"'>
job:eval(
static-base-uri(),
|
* The following [[RESTXQ]] function will either return the result of a previously started job or raise an error:
<syntaxhighlight pre lang="'xquery"'>
declare %rest:path('/result/{$id}') function local:result($id) {
job:result($id)
</syntaxhighlight>
* The following query demonstrates how the results of an executed query can be returned within the same query (see below why you should avoid this pattern in practice):
<syntaxhighlight pre lang="'xquery"'>
let $query := job:eval('(1 to 10000000)[. = 1]', map { }, map { 'cache': true() })
return (