-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathtasks.py
121 lines (103 loc) · 4.83 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch B.V. licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import warnings
from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
class TasksClient(NamespacedClient):
@query_params(
"actions",
"detailed",
"group_by",
"nodes",
"parent_task_id",
"timeout",
"wait_for_completion",
)
async def list(self, params=None, headers=None):
"""
Returns a list of tasks.
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.10/tasks.html>`_
.. warning::
This API is **experimental** so may include breaking changes
or be removed in a future version
:arg actions: A comma-separated list of actions that should be
returned. Leave empty to return all.
:arg detailed: Return detailed task information (default: false)
: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
:arg parent_task_id: Return tasks with specified parent task id
(node_id:task_number). Set to -1 to return all.
:arg timeout: Explicit operation timeout
:arg wait_for_completion: Wait for the matching tasks to
complete (default: false)
"""
return await self.transport.perform_request(
"GET", "/_tasks", params=params, headers=headers
)
@query_params("actions", "nodes", "parent_task_id", "wait_for_completion")
async def cancel(self, task_id=None, params=None, headers=None):
"""
Cancels a task, if it can be cancelled through an API.
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.10/tasks.html>`_
.. warning::
This API is **experimental** so may include breaking changes
or be removed in a future version
:arg task_id: Cancel the task with specified task id
(node_id:task_number)
:arg actions: A comma-separated list of actions that should be
cancelled. Leave empty to cancel all.
: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
:arg parent_task_id: Cancel tasks with specified parent task id
(node_id:task_number). Set to -1 to cancel all.
:arg wait_for_completion: Should the request block until the
cancellation of the task and its descendant tasks is completed. Defaults
to false
"""
return await self.transport.perform_request(
"POST",
_make_path("_tasks", task_id, "_cancel"),
params=params,
headers=headers,
)
@query_params("timeout", "wait_for_completion")
async def get(self, task_id=None, params=None, headers=None):
"""
Returns information about a task.
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.10/tasks.html>`_
.. warning::
This API is **experimental** so may include breaking changes
or be removed in a future version
: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)
"""
if task_id in SKIP_IN_PATH:
warnings.warn(
"Calling client.tasks.get() without a task_id is deprecated "
"and will be removed in v8.0. Use client.tasks.list() instead.",
category=DeprecationWarning,
stacklevel=3,
)
return await self.transport.perform_request(
"GET", _make_path("_tasks", task_id), params=params, headers=headers
)