Files
opensearch-pyd/elasticsearch/client/tasks.py
T

73 lines
3.1 KiB
Python
Raw Normal View History

2016-03-22 21:04:07 +01:00
from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
2019-05-10 09:16:33 -06:00
2016-03-22 21:04:07 +01:00
class TasksClient(NamespacedClient):
2019-05-10 09:16:33 -06:00
@query_params(
"actions",
"detailed",
"group_by",
"nodes",
"parent_task_id",
"timeout",
2019-12-17 22:31:35 +01:00
"wait_for_completion",
2019-05-10 09:16:33 -06:00
)
2017-07-31 19:17:52 -04:00
def list(self, params=None):
2016-03-22 21:04:07 +01:00
"""
2019-12-17 22:31:35 +01:00
Returns a list of tasks.
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html>`_
2016-03-22 21:04:07 +01:00
2019-12-17 22:31:35 +01:00
:arg actions: A comma-separated list of actions that should be
returned. Leave empty to return all.
2016-03-22 21:04:07 +01:00
:arg detailed: Return detailed task information (default: false)
2019-12-17 22:31:35 +01:00
:arg group_by: Group tasks by nodes or parent/child
relationships Valid choices: nodes, parents, none Default: nodes
:arg nodes: A comma-separated list of node IDs or names to limit
the returned information; use `_local` to return information from the
node you're connecting to, leave empty to get information from all nodes
2017-10-26 14:51:37 +02:00
:arg parent_task_id: Return tasks with specified parent task id
2016-05-17 14:12:39 +02:00
(node_id:task_number). Set to -1 to return all.
2019-12-17 22:31:35 +01:00
:arg timeout: Explicit operation timeout
:arg wait_for_completion: Wait for the matching tasks to
complete (default: false)
2016-03-22 21:04:07 +01:00
"""
2019-05-10 09:16:33 -06:00
return self.transport.perform_request("GET", "/_tasks", params=params)
2016-03-22 21:04:07 +01:00
2019-05-10 09:16:33 -06:00
@query_params("actions", "nodes", "parent_task_id")
2016-03-22 21:04:07 +01:00
def cancel(self, task_id=None, params=None):
"""
2019-12-17 22:31:35 +01:00
Cancels a task, if it can be cancelled through an API.
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html>`_
2016-03-22 21:04:07 +01:00
2016-05-17 14:12:39 +02:00
:arg task_id: Cancel the task with specified task id
(node_id:task_number)
2016-03-22 21:04:07 +01:00
:arg actions: A comma-separated list of actions that should be
cancelled. Leave empty to cancel all.
2019-12-17 22:31:35 +01:00
:arg nodes: A comma-separated list of node IDs or names to limit
the returned information; use `_local` to return information from the
node you're connecting to, leave empty to get information from all nodes
2017-10-26 14:51:37 +02:00
:arg parent_task_id: Cancel tasks with specified parent task id
2016-05-17 14:12:39 +02:00
(node_id:task_number). Set to -1 to cancel all.
2016-03-22 21:04:07 +01:00
"""
2019-05-10 09:16:33 -06:00
return self.transport.perform_request(
"POST", _make_path("_tasks", task_id, "_cancel"), params=params
)
2016-03-22 21:04:07 +01:00
2019-12-17 22:31:35 +01:00
@query_params("timeout", "wait_for_completion")
def get(self, task_id, params=None):
2016-06-28 16:38:32 +02:00
"""
2019-12-17 22:31:35 +01:00
Returns information about a task.
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html>`_
2016-06-28 16:38:32 +02:00
2019-12-17 22:31:35 +01:00
:arg task_id: Return the task with specified id
(node_id:task_number)
:arg timeout: Explicit operation timeout
:arg wait_for_completion: Wait for the matching tasks to
complete (default: false)
2016-06-28 16:38:32 +02:00
"""
2019-12-17 22:31:35 +01:00
if task_id in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'task_id'.")
2019-05-10 09:16:33 -06:00
return self.transport.perform_request(
"GET", _make_path("_tasks", task_id), params=params
)