This page was generated
August  8,  2011
2:23  AM
XQuery Built-In and Modules Function Reference

Module: Admin Library - Scheduler Functions

The Admin module is an XQuery library module that allows you to script administrative tasks that you otherwise would need the Admin Interface to perform. Most functions in this library perform adminstrative tasks and therefore require the user who runs the XQuery program to have the Admin role.

Many of these functions provide new configuration information. In most cases, you must save the configuration (with admin:save-configuration, for example) in the same statement that you use the functions in order for them to take effect.

To use the Admin module as part of your own XQuery module, include the following line in your XQuery prolog:

import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy" ;

The library namespace prefix admin is not predefined in the server.

Function Summary
admin:group-add-scheduled-task This function adds one or more scheduled tasks to the specified group.
admin:group-daily-scheduled-task This function constructs a task to be invoked at daily intervals.
admin:group-delete-scheduled-task This function deletes one or more scheduled tasks from the specified group.
admin:group-get-scheduled-tasks This function returns all of the tasks scheduled for the specified group.
admin:group-hourly-scheduled-task This function constructs a task to be invoked at hourly intervals.
admin:group-minutely-scheduled-task This function constructs a task to be invoked at intervals defined in terms of minutes.
admin:group-monthly-scheduled-task This function constructs a task to be invoked at monthly intervals.
admin:group-one-time-scheduled-task This function constructs a task to be invoked once, at a specific calendar day and time.
admin:group-weekly-scheduled-task This function constructs a task to be invoked at weekly intervals.
Function Detail
admin:group-add-scheduled-task(
$config as element(configuration),
$group-id as xs:unsignedLong,
$scheduled-tasks as element(gr:scheduled-task)*
)  as   element(configuration)
Summary:

This function adds one or more scheduled tasks to the specified group.

Parameters:
$config : A configuration specification, typically as returned from one of the Admin module functions.
$group-id : The ID of the group on which the scheduled tasks are configured. Typically, this is the result of an admin:group-get-id call.
$scheduled-tasks : One or more scheduled tasks, such as those created by the task-create functions.

Example:
  xquery version "1.0-ml";
  import module namespace admin = "http://marklogic.com/xdmp/admin" 
      at "/MarkLogic/admin.xqy";

  let $config := admin:get-configuration()
 
  let $task := admin:group-hourly-scheduled-task(
      "/Scheduler_test.xqy",
      "/Docs",
      2,
      30,
      xdmp:database("Documents"),
      0,
      xdmp:user("Jim"), 
      0)

  let $addTask := admin:group-add-scheduled-task($config, 
      admin:group-get-id($config, "Default"), $task)

  return 
      admin:save-configuration($addTask)
 
  (: Creates an hourly scheduled task and adds it to the "Default" group. :)
   

admin:group-daily-scheduled-task(
$task-path as xs:string,
$task-root as xs:string,
$task-period as xs:positiveInteger,
$task-start-time as xs:time,
$task-database as xs:unsignedLong,
$task-modules as xs:unsignedLong,
$task-user as xs:unsignedLong,
$task-host as xs:unsignedLong?
)  as   element(gr:scheduled-task)
Summary:

This function constructs a task to be invoked at daily intervals.

Parameters:
$task-path : The name of the module to be invoked. The task path must begin with a forward slash (/) and cannot contain a question mark '?', colon ':' or pound '#' character.
$task-root : The root directory (filesystem) or URI root (database) that contains the module. For example, if the module is located in the filesystem under MarkLogic/Docs, specify Docs.
$task-period : The number of days to elapse between each invocation of the module.
$task-start-time : The time of day (in 24:00 notation) to invoke the module.
$task-database : The id of the database on which the module is to be invoked.
$task-modules : The id of the modules database. For example, xdmp:database("Modules"). To specify the filesystem, use 0.
$task-user : The id of the user with permission to invoke the module. For example, xdmp:user("Jim").
$task-host : The id of the host on which to invoke the module. Leave empty, (), to specify all hosts.

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
      at "/MarkLogic/admin.xqy";

  let $config := admin:get-configuration()
  return
     admin:group-daily-scheduled-task(
        "/Scheduler_test.xqy",
        "/Docs",
        2,
        xs:time("09:30:00"),
        xdmp:database("Documents"),
        xdmp:database("Modules"),
        xdmp:user("Jim"), 
        0)

  (: returns a daily scheduled task. :)
   

admin:group-delete-scheduled-task(
$config as element(configuration),
$group-id as xs:unsignedLong,
$scheduled-tasks as element(gr:scheduled-task)*
)  as   element(configuration)
Summary:

This function deletes one or more scheduled tasks from the specified group.

Parameters:
$config : A configuration specification, typically as returned from one of the Admin module functions.
$group-id : The ID of the group on which the scheduled tasks are configured. Typically, this is the result of an admin:group-get-id call.
$scheduled-tasks : One or more scheduled tasks.

Example:
  xquery version "1.0-ml";
  import module namespace admin = "http://marklogic.com/xdmp/admin" 
      at "/MarkLogic/admin.xqy";

  let $config := admin:get-configuration()
  let $group := admin:group-get-id($config, "Default")
  let $tasks := admin:group-get-scheduled-tasks($config, $group)

  return  
   admin:group-delete-scheduled-task($config, $group, $tasks)
  
   (: Returns a configuration element with the scheduled tasks in the 
      "Default" group deleted -- use admin:save-configuration
      to save the changes to the configuration or pass the configuration
      to other Admin API functions to make other changes. :)
   

admin:group-get-scheduled-tasks(
$config as element(configuration),
$group-id as xs:unsignedLong
)  as   element(gr:scheduled-task)*
Summary:

This function returns all of the tasks scheduled for the specified group.

Parameters:
$config : A configuration specification, typically as returned from one of the Admin module functions.
$group-id : The ID of the group on which the scheduled tasks are configured. Typically, this is the result of an admin:group-get-id call.

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
      at "/MarkLogic/admin.xqy";

  let $config := admin:get-configuration()
  return
    admin:group-get-scheduled-tasks($config, 
      admin:group-get-id($config, "Default"))
  
   =>

  <scheduled-task xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://marklogic.com/xdmp/group">
    <task-path>/Scheduler_test.xqy</task-path>
    <task-root>/Docs</task-root>
    <task-type>minutely</task-type>
    <task-period>15</task-period>
    <task-days/>
    <task-timestamp>2009-02-27T12:16:06.152-08:00</task-timestamp>
    <task-database>3439178527237237454</task-database>
    <task-modules>0</task-modules>
    <task-user>10677693687367813363</task-user>
  </scheduled-task>
   

admin:group-hourly-scheduled-task(
$task-path as xs:string,
$task-root as xs:string,
$task-period as xs:positiveInteger,
$task-minute as xs:nonNegativeInteger,
$task-database as xs:unsignedLong,
$task-modules as xs:unsignedLong,
$task-user as xs:unsignedLong,
$task-host as xs:unsignedLong?
)  as   element(gr:scheduled-task)
Summary:

This function constructs a task to be invoked at hourly intervals.

Parameters:
$task-path : The name of the module to be invoked. The task path must begin with a forward slash (/) and cannot contain a question mark '?', colon ':' or pound '#' character.
$task-root : The root directory (filesystem) or URI root (database) that contains the module. For example, if the module is located in the filesystem under MarkLogic/Docs, specify Docs.
$task-period : The number of hours to elapse between each invocation of the module.
$task-minute : The number of minutes after the hour to invoke the module. This value must be 59 or less. Note that this setting does not add to the task-period value.
$task-database : The id of the database on which the module is to be invoked.
$task-modules : The id of the modules database. For example, xdmp:database("Modules"). To specify the filesystem, use 0.
$task-user : The id of the user with permission to invoke the module. For example, xdmp:user("Jim").
$task-host : The id of the host on which to invoke the module. Leave empty, (), to specify all hosts.

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
      at "/MarkLogic/admin.xqy";

  let $config := admin:get-configuration()
  return
     admin:group-hourly-scheduled-task(
         "/Scheduler_test.xqy",
         "/Docs",
         2,
         30,
         xdmp:database("Documents"),
         0,
         xdmp:user("Jim"), 
         0)
  
    (: returns an hourly scheduled task. :)
   

admin:group-minutely-scheduled-task(
$task-path as xs:string,
$task-root as xs:string,
$task-period as xs:positiveInteger,
$task-database as xs:unsignedLong,
$task-modules as xs:unsignedLong,
$task-user as xs:unsignedLong,
$task-host as xs:unsignedLong?
)  as   element(gr:scheduled-task)
Summary:

This function constructs a task to be invoked at intervals defined in terms of minutes.

Parameters:
$task-path : The name of the module to be invoked. The task path must begin with a forward slash (/) and cannot contain a question mark '?', colon ':' or pound '#' character.
$task-root : The root directory (filesystem) or URI root (database) that contains the module. For example, if the module is located in the filesystem under MarkLogic/Docs, specify Docs.
$task-period : The number of minutes to elapse between each invocation of the module.
$task-database : The id of the database on which the module is to be invoked.
$task-modules : The id of the modules database. For example, xdmp:database("Modules"). To specify the filesystem, use 0.
$task-user : The id of the user with permission to invoke the module. For example, xdmp:user("Jim").
$task-host : The id of the host on which to invoke the module. Leave empty, (), to specify all hosts.

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
      at "/MarkLogic/admin.xqy";

  let $config := admin:get-configuration()
  return
     admin:group-minutely-scheduled-task(
        "/Scheduler_test.xqy",
        "/Docs",
        45,
        xdmp:database("Documents"),
        0,
        xdmp:user("Jim"), 
        0)

    (: returns a minutely scheduled task. :)
   

admin:group-monthly-scheduled-task(
$task-path as xs:string,
$task-root as xs:string,
$task-period as xs:positiveInteger,
$task-month-day as xs:unsignedLong,
$task-start-time as xs:time,
$task-database as xs:unsignedLong,
$task-modules as xs:unsignedLong,
$task-user as xs:unsignedLong,
$task-host as xs:unsignedLong?
)  as   element(gr:scheduled-task)
Summary:

This function constructs a task to be invoked at monthly intervals.

Parameters:
$task-path : The name of the module to be invoked. The task path must begin with a forward slash (/) and cannot contain a question mark '?', colon ':' or pound '#' character.
$task-root : The root directory (filesystem) or URI root (database) that contains the module. For example, if the module is located in the filesystem under MarkLogic/Docs, specify Docs.
$task-period : The number of months to elapse between each invocation of the module.
$task-month-day : The day of the month to invoke the module.
$task-start-time : The time of day (in 24:00 notation) to invoke the module.
$task-database : The id of the database on which the module is to be invoked.
$task-modules : The id of the modules database. For example, xdmp:database("Modules"). To specify the filesystem, use 0.
$task-user : The id of the user with permission to invoke the module. For example, xdmp:user("Jim").
$task-host : The id of the host on which to invoke the module. Leave empty, (), to specify all hosts.

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
      at "/MarkLogic/admin.xqy";

  let $config := admin:get-configuration()
  return
     admin:group-monthly-scheduled-task(
        "/Scheduler_test.xqy",
        "/Docs",
	2,
	3,
	xs:time("14:42:52"),
        xdmp:database("Documents"),
        0,
        xdmp:user("Jim"), 
	0)

     (: returns a monthly scheduled task. :) 
   

admin:group-one-time-scheduled-task(
$task-path as xs:string,
$task-root as xs:string,
$task-start as xs:dateTime,
$task-database as xs:unsignedLong,
$task-modules as xs:unsignedLong,
$task-user as xs:unsignedLong,
$task-host as xs:unsignedLong?
)  as   element(gr:scheduled-task)
Summary:

This function constructs a task to be invoked once, at a specific calendar day and time.

Parameters:
$task-path : The name of the module to be invoked. The task path must begin with a forward slash (/) and cannot contain a question mark '?', colon ':' or pound '#' character.
$task-root : The root directory (filesystem) or URI root (database) that contains the module. For example, if the module is located in the filesystem under MarkLogic/Docs, specify Docs.
$task-start : The date and time on which the task is to start.
$task-database : The id of the database on which the module is to be invoked.
$task-modules : The id of the modules database. For example, xdmp:database("Modules"). To specify the filesystem, use 0.
$task-user : The id of the user with permission to invoke the module. For example, xdmp:user("Jim").
$task-host : The id of the host on which to invoke the module. Leave empty, (), to specify all hosts.

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
      at "/MarkLogic/admin.xqy";

  let $config := admin:get-configuration()
  return
     admin:group-one-time-scheduled-task(
        "/Scheduler_test.xqy",
        "/Docs",
        xs:dateTime("2009-03-29T14:42:52"),
        xdmp:database("Documents"),
        xdmp:database("Documents"),
        xdmp:user("Jim"), 
	admin:host-get-id($config, xdmp:host-name()))

    (: returns a one-time scheduled task. :)
   

admin:group-weekly-scheduled-task(
$task-path as xs:string,
$task-root as xs:string,
$task-period as xs:positiveInteger,
$task-days as xs:string+,
$task-start-time as xs:time,
$task-database as xs:unsignedLong,
$task-modules as xs:unsignedLong,
$task-user as xs:unsignedLong,
$task-host as xs:unsignedLong?
)  as   element(gr:scheduled-task)
Summary:

This function constructs a task to be invoked at weekly intervals.

Parameters:
$task-path : The name of the module to be invoked. The task path must begin with a forward slash (/) and cannot contain a question mark '?', colon ':' or pound '#' character.
$task-root : The root directory (filesystem) or URI root (database) that contains the module. For example, if the module is located in the filesystem under MarkLogic/Docs, specify Docs.
$task-period : The number of weeks to elapse between each invocation of the module.
$task-days : One or more days on the specified week to invoke the module
$task-start-time : The time of day (in 24:00 notation) to invoke the module.
$task-database : The id of the database on which the module is to be invoked.
$task-modules : The id of the modules database. For example, xdmp:database("Modules"). To specify the filesystem, use 0.
$task-user : The id of the user with permission to invoke the module. For example, xdmp:user("Jim").
$task-host : The id of the host on which to invoke the module. Leave empty, (), to specify all hosts.

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
      at "/MarkLogic/admin.xqy";

  let $config := admin:get-configuration()
  return
     admin:group-weekly-scheduled-task(
        "/Scheduler_test.xqy",
        "/Docs",
        2,
        ("Monday", "Wednesday"),
        xs:time("14:42:52"),
        xdmp:database("Documents"),
        xdmp:database("Documents"),
        xdmp:user("Jim"), 
        admin:host-get-id($config, xdmp:host-name()))

     (: returns a weekly scheduled task. :)