Chapter 5. The Task Server

MarkLogic’s Task Server provides a way to schedule work asynchronously. By default, up to 16 tasks will run at the same time on the standard queue, along with 16 tasks on the high-priority queue. Recipes in this chapter show how to remove tasks from the queue, which normally only happens if the queue is wiped by a MarkLogic restart.

Cancel Active Tasks on the Task Server


There are active tasks being executed on the Task Server, and you’d like to cancel some or all of them.


Applies to MarkLogic versions 7 or higher

xquery version "1.0-ml";

declare namespace hs="";
declare namespace ss="";

let $max-task-duration := xs:dayTimeDuration("PT7M")
let $min-retries := 2
(: set $user-ids to desired sequence of ids :)
let $user-ids := xdmp:get-current-userid()
let $compare-time := fn:current-dateTime() - $max-task-duration
for $host as xs:unsignedLong in xdmp:hosts()
let $task-server-id :=
let $requests :=
  xdmp:server-status($host, $task-server-id)//ss:request-status[
    (: and ss:user = 7071164300007443533 :)
    (: and ss:retry-count >= $min-retries :)
    and ss:request-text = "/some/module/uri.xqy"
    and ss:start-time < $compare-time
return (
    "There are currently", fn:count($requests),
    "matching requests on host", xdmp:host-name($host)
  for $request in $requests
  let $request-id as xs:unsignedLong ...

Get MarkLogic Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.