Categories:

System functions (System Control)

SYSTEM$CANCEL_TASK_GRAPH

Cancels one or all runs of a task graph, stopping work that is queued or scheduled under the targeted run or runs and marking any task that is already executing so that it completes with a CANCELLED state.

In this function, a task graph is either a classic task tree rooted at a root task or a task graph object. For more information about tasks, see Introduction to tasks.

See also:

SYSTEM$TASK_DEPENDENTS_ENABLE , CURRENT_TASK_GRAPHS , COMPLETE_TASK_GRAPHS

Syntax

SYSTEM$CANCEL_TASK_GRAPH(
    { ROOT_NAME => '<root_task_name>' | GRAPH_NAME => '<task_graph_name>' }
    [ , CANCEL_FINALIZER => TRUE | FALSE ]
    [ , GRAPH_RUN_UUID => '<uuid>' ] )

Arguments

You must pass every argument by name (for example, GRAPH_NAME => 'my_graph'). Positional calls are rejected. Exactly one of ROOT_NAME or GRAPH_NAME is required.

ROOT_NAME => 'root_task_name'

The fully qualified name of the root task of a classic task tree.

Required unless you specify GRAPH_NAME. This argument is mutually exclusive with GRAPH_NAME.

If the name you pass belongs to a task that isn’t a root task, the call fails with an error that identifies the correct task name or task graph to use.

GRAPH_NAME => 'task_graph_name'

The fully qualified name of a task graph object.

Required unless you specify ROOT_NAME. This argument is mutually exclusive with ROOT_NAME.

CANCEL_FINALIZER => TRUE | FALSE

Specifies whether the graph’s finalizer task is also cancelled.

By default (FALSE), the finalizer task is spared and still runs to completion after the rest of the graph is cancelled. Set this argument to TRUE to also cancel the finalizer task.

Default: FALSE

GRAPH_RUN_UUID => 'uuid'

The ID of one specific graph run to cancel. This is the GRAPH_RUN_GROUP_ID value for the run, which you can retrieve from the CURRENT_TASK_GRAPHS or COMPLETE_TASK_GRAPHS function.

If you omit this argument, the function cancels every currently incomplete run of the named task graph. This is the default behavior.

This argument currently supports only one run ID per call.

Returns

Returns a string that describes the outcome of the call. The exact message depends on how many matching runs the function finds and their state. For example, the function returns a message that reports one of the following outcomes:

  • The number of graph runs that were cancelled, noting whether the finalizer task was spared (for example, 2 graph run(s) cancelled (except finalizer).) or included (for example, 2 graph run(s) cancelled.).

  • No matching run was found to cancel, because the run already finished or nothing is currently running. The message asks you to confirm the run that you intended to cancel and try again.

  • The targeted run or runs were already being cancelled by an earlier call. The message reports how many runs are already cancelling from an earlier request.

  • The targeted run or runs finished in the brief window before the cancellation took effect. The message explains that the runs might have completed while the cancellation was in progress and suggests that you check the run status and retry if needed.

Access control requirements

To call this function, you must use a role that has one of the following privileges on the task or task graph that you specify:

  • OPERATE
  • OWNERSHIP

Usage notes

  • ROOT_NAME and GRAPH_NAME are mutually exclusive, and exactly one of them is required per call. Supplying both, or neither, is an error.

  • Only named-argument syntax is supported. Positional calls are rejected.

  • Passing any argument as NULL is rejected. To omit an optional argument, leave it out of the call. For example, you can’t pass GRAPH_RUN_UUID => NULL to mean “omit it.”

  • If you omit GRAPH_RUN_UUID, the function cancels all currently incomplete runs of the task graph, not just one. To cancel a single run, pass that run’s GRAPH_RUN_GROUP_ID value in GRAPH_RUN_UUID. You can retrieve this value from the CURRENT_TASK_GRAPHS or COMPLETE_TASK_GRAPHS function.

  • The finalizer task, if the graph has one, isn’t cancelled unless you explicitly set CANCEL_FINALIZER => TRUE.

  • Cancellation isn’t instantaneous for in-flight work. A task that is already running finishes its current execution and is then marked CANCELLED, rather than being interrupted mid-execution.

Examples

Cancel every run of a classic task tree by specifying its root task name:

SELECT SYSTEM$CANCEL_TASK_GRAPH(ROOT_NAME => 'mydb.myschema.my_root_task');

+----------------------------------------------+
| SYSTEM$CANCEL_TASK_GRAPH                     |
|----------------------------------------------|
| 3 graph run(s) cancelled (except finalizer). |
+----------------------------------------------+

Cancel every run of a task graph object by specifying its name:

SELECT SYSTEM$CANCEL_TASK_GRAPH(GRAPH_NAME => 'mydb.myschema.my_task_graph');

+----------------------------------------------+
| SYSTEM$CANCEL_TASK_GRAPH                     |
|----------------------------------------------|
| 2 graph run(s) cancelled (except finalizer). |
+----------------------------------------------+

Cancel one specific run of a task graph by specifying the run ID:

SELECT SYSTEM$CANCEL_TASK_GRAPH(
    GRAPH_NAME => 'mydb.myschema.my_task_graph',
    GRAPH_RUN_UUID => 'a1b2c3d4-e5f6-7890-abcd-ef1234567890');

+----------------------------------------------+
| SYSTEM$CANCEL_TASK_GRAPH                     |
|----------------------------------------------|
| 1 graph run(s) cancelled (except finalizer). |
+----------------------------------------------+

Cancel every run of a task graph, including its finalizer task:

SELECT SYSTEM$CANCEL_TASK_GRAPH(
    GRAPH_NAME => 'mydb.myschema.my_task_graph',
    CANCEL_FINALIZER => TRUE);

+----------------------------------+
| SYSTEM$CANCEL_TASK_GRAPH         |
|----------------------------------|
| 1 graph run(s) cancelled.        |
+----------------------------------+