(: unregister job :)
job:remove('cleanup', map { 'service': true() })
</syntaxhighlightpre>
'''Some more notes:'''
<pre lang='xquery'>
job:eval("1+3", (), map { 'cache': true() })
</syntaxhighlightpre>
* A happy birthday mail will be sent at the given date:
<pre lang='xquery'>
job:eval("import module namespace mail='mail'; mail:send('Happy birthday!')",
(), map { 'start': '2018-09-01T06:00:00' })}}
</syntaxhighlightpre>
* 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:
<pre lang='xquery'>
job:remove($id)
};
</syntaxhighlightpre>
* 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 lang='xquery'>
job:eval("prof:sleep(1500)", (), map { 'interval': 'PT1S', 'end': 'PT10S' })
</syntaxhighlightpre>
* The query in the specified file will be evaluated once:
<pre lang='xquery'>
job:eval(xs:anyURI('cleanup.xq'))
</syntaxhighlightpre>
* The following expression, if stored in a file, will be evaluated every 5 seconds:
<pre lang='xquery'>
map { 'start': 'PT5S' }
)
</syntaxhighlightpre>
|}
job:result($id)
};
</syntaxhighlightpre>
* 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):
<pre lang='xquery'>
job:result($query)
)
</syntaxhighlightpre>
Queries of this kind can cause deadlocks! If the original query and the new query perform updates on the same database, the second query will only be run after the first one has been executed, and the first query will wait for the second query forever. You should resort to {{Function|XQuery|xquery:fork-join}} if you want to have full control on parallel query execution.
|}
| '''Examples'''
| <code>job:list-details()</code> returns information on the currently running job and possibly others:
<syntaxhighlight pre lang="xml">
<job id="job1" type="XQuery" state="running" user="admin" duration="PT0.001S">
XQUERY job:list-details()
</job>
</syntaxhighlightpre>
|}