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+

xquery version "1.0-ml";
declare namespace hs = "";
declare namespace ss = "";
let $max-task-duration := xs:dayTimeDuration("PT7M")
let $min-retries := 2
let $user-ids := xdmp:get-current-userid() (: replace with desired sequence of ids :)
let $compare-time := fn:current-dateTime() - $max-task-duration
for $host as xs:unsignedLong in xdmp:hosts()
let $task-server-id := xdmp:host-status($host)//hs: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 (
  text{"There are currently", fn:count($requests), "matching requests on host", xdmp:host-name($host)},
  for $request in $requests
  let $request-id as xs:unsignedLong := $request/ss:request-id
  let $start as xs:dateTime := $request/ss:start-time
  return (
      $request-id, "started:", $start, "duration:", (fn:current-dateTime() - $start),
      if (fn:true()) then (
        xdmp:request-cancel($host, $request/ss:server-id, $request-id),
        "-- cancel issued"
      else ()

Required Privileges:



Under certain circumstances, it may become necessary to cancel all the tasks on the task server that match a specific pattern. This may be due to human error, such as someone performing a “re-replicate all documents in domain”, or due to specific conditions occurring within a production application. Note that this recipe only cancels tasks that are actively running. Queued tasks are not affected.

The privilege is required. The user running this script must also have either (to cancel requests running as that user) or (to cancel any other requests).

As written, this script uses multiple filters to only show tasks that have been executing for over 7 minutes, have already been retried twice, and are associated with a specific module. Other criteria that may be useful include the user the task is running under. Also note the usage of a fixed conditional that can be toggled to perform the xdmp:request-cancel(). This allows you to test your query criteria iteratively until you are satisfied you will only cancel the desired tasks.

Below is an example of a request record returned by xdmp:server-status. Filters can be written for any of these fields.

<request-status xmlns="">

Learn More

Cancel Active and Queued Tasks on the Task Server

Learn how to cancel requests that have queued on the Task Server without clearing the entire queue or restart the host.

Administering MarkLogic Server Course

This course provides the necessary hands-on experience and knowledge to install, deploy, configure, monitor and maintain MarkLogic.

Administrator's Guide Documentation

This guide reviews over administrative tasks for MarkLogic that have the ability to run on all platforms.

This website uses cookies.

By continuing to use this website you are giving consent to cookies being used in accordance with the MarkLogic Privacy Statement.